A comprehensive collection of data structures, algorithms, and problem-solving patterns with Python implementations.
- Sliding Window
- Two Pointers
- Binary Search
- Prefix Sum
- Monotonic Stack
- DFS & BFS
- Dynamic Programming
- Greedy
- Backtracking
- Clone this repository
- Navigate to the specific pattern or data structure you want to study
- Read the README for that topic
- Use the provided templates to solve problems
- Practice with the example problems
- Start with data structures to understand the building blocks
- Move to algorithm patterns to learn problem-solving approaches
- Use the templates as starting points for your solutions
- Each pattern includes a template with common variations
- Data structures include basic operations and common use cases
- Utilities provide helper functions for common operations
- Understand the Problem: Read carefully and identify the core requirements
- Choose the Right Pattern: Match the problem to an appropriate algorithm pattern
- Select Data Structures: Pick the most efficient data structures for your solution
- Implement: Use the templates as starting points
- Test: Verify your solution with edge cases
- Optimize: Analyze time and space complexity
| Pattern | Time Complexity | Space Complexity | Use Cases |
|---|---|---|---|
| Sliding Window | O(n) | O(1) | Subarray problems |
| Two Pointers | O(n) | O(1) | Sorted array problems |
| Binary Search | O(log n) | O(1) | Search in sorted data |
| DFS/BFS | O(V + E) | O(V) | Graph traversal |
| DP | O(n²) to O(n) | O(n) to O(1) | Optimization problems |
Feel free to contribute by:
- Adding more example problems
- Improving existing templates
- Adding new patterns or data structures
- Fixing bugs or improving documentation
This repository is for educational purposes. Feel free to use and modify the code for learning and practice.