๐ Python Data Structures & Algorithms¶
A comprehensive collection of 190 DSA questions with implementations, thought processes, and complexity analysis across 20 categories.
๐ Quick Reference¶
| # | Category | Questions | Key Topics |
|---|---|---|---|
| 01 | Arrays | 12 | Two pointers, sliding window, prefix sum, Kadane's |
| 02 | Strings | 10 | Palindromes, anagrams, pattern matching, atoi |
| 03 | Stacks | 9 | Monotonic stack, RPN, parentheses, histogram |
| 04 | Queues | 7 | Sliding window max, circular queue, task scheduler |
| 05 | Hashing | 9 | Frequency maps, LRU cache, valid sudoku, top k |
| 06 | Linked Lists | 10 | Reverse, cycle detection, merge, palindrome |
| 07 | Trees | 12 | BST, traversals, LCA, serialize, diameter |
| 08 | Graphs | 12 | BFS/DFS, Dijkstra, union find, topological sort |
| 09 | Dynamic Programming | 13 | Knapsack, LCS, LIS, edit distance, house robber |
| 10 | Sorting & Searching | 11 | Quick/merge/heap sort, binary search variants |
| 11 | Backtracking | 11 | N-Queens, subsets, permutations, Sudoku solver |
| 12 | Trie | 7 | Prefix tree, word search II, autocomplete |
| 13 | Heaps | 9 | Median finder, merge k lists, sliding window median |
| 14 | Bit Manipulation | 10 | XOR tricks, Hamming weight, counting bits, max XOR |
| 15 | Advanced Strings | 8 | KMP, Rabin-Karp, Z-Algorithm, Manacher's, suffix array |
| 16 | Advanced Trees | 4 | AVL, Red-Black, B-Tree, B+ Tree implementations |
| 17 | Sliding Window | 9 | Variable/fixed window, substring concatenation |
| 18 | Greedy | 9 | Activity selection, Huffman coding, jump game |
| 19 | Math & Number Theory | 10 | Sieve, GCD, modular exp, reservoir sampling |
| 20 | Design Problems | 8 | Logger, rate limiter, elevator, pub-sub, thread pool |
๐ฏ How to Use¶
# Run all demos
python python-dsa/main.py
# Run a specific category
python python-dsa/01_arrays/questions.py
python python-dsa/03_stacks/questions.py
# List available categories
python python-dsa/main.py -l
๐ Question Format¶
Every question follows a consistent structure:
- QUESTION โ Problem statement with example
- THOUGHT PROCESS โ Step-by-step reasoning from brute force to optimal
- COMPLEXITY โ Time and space analysis
- EDGE CASES โ Empty input, single element, duplicates, negatives
- IMPLEMENTATION โ Clean Python code with optimal approach
๐ง Core DSA Problem-Solving Framework¶
- Understand โ Input/output types, constraints, brute force first
- Identify Pattern โ Two pointers, sliding window, BFS/DFS, DP, etc.
- Analyze Complexity โ Time vs space trade-offs
- Test Edge Cases โ Empty, single, duplicates, negatives
โก Key DSA Patterns Cheatsheet¶
| Pattern | When to Use |
|---|---|
| Two Pointers | Sorted array, palindrome, in-place |
| Sliding Window | Contiguous subarray/substring |
| Monotonic Stack | Next greater/smaller element |
| Slow/Fast Pointers | Cycle detection, middle of list |
| BFS | Shortest path, level order |
| DFS | Exhaustive search, path finding |
| Binary Search | Sorted data, boundary finding |
| Topological Sort | Dependency ordering |
| Union Find | Connected components |
| DP: Memoization | Overlapping subproblems |
| DP: Tabulation | Bottom-up optimization |
| Backtracking | All permutations/combinations |