Skip to content

Conversation

@codomposer
Copy link

Add New Algorithm, Data Structure, and Design Pattern

Summary

This PR adds three new implementations to enhance the interview preparation repository:

  • Algorithm: Topological Sort
  • Data Structure: Trie (Prefix Tree)
  • Design Pattern: Strategy Pattern

Changes

🔢 Algorithm - Topological Sort

  • Implemented Kahn's algorithm (BFS-based approach)
  • Implemented DFS-based approach
  • Includes cycle detection for directed graphs
  • Time complexity: O(V + E)
  • Use cases: task scheduling, build order, course scheduling, dependency resolution

🌳 Data Structure - Trie

  • Complete Trie (prefix tree) implementation
  • Operations: insert, search, startsWith, remove
  • Time complexity: O(m) for all operations (m = string length)
  • Space complexity: O(ALPHABET_SIZE * N * M)
  • Applications: string retrieval, autocomplete, word frequency statistics

🎨 Design Pattern - Strategy Pattern

  • Abstract strategy interface
  • Three concrete strategy implementations (A, B, C)
  • Context class for strategy management
  • Test code with practical sorting example
  • Pattern documentation with advantages and use cases

Documentation Updates

  • ✅ Updated README.md (Chinese) with all new implementations
  • ✅ Updated README_en.md (English) with all new implementations
  • ✅ Added detailed explanations, complexity analysis, and applications
  • ✅ Included code examples and test functions

Testing

All implementations include test functions:

  • testTopologicalSort()- Tests both algorithms with sample graphs
  • testTrie() - Tests insert, search, prefix matching, and deletion
  • testStrategyPattern() - Demonstrates strategy switching and practical sorting example

Code Quality

  • ✅ Follows existing codebase style and conventions
  • ✅ Comprehensive inline comments in Chinese
  • ✅ Well-structured and production-ready
  • ✅ No breaking changes to existing code

Fixes #12

@codomposer codomposer closed this Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[讨论] 本仓库的建议、讨论等方面

1 participant