All Patterns
The full list of 25 DSA patterns organized by category, with a one-line summary of each.
The 25 patterns, each in its own page with trigger conditions, an invariant, a template, a worked example, variants, pitfalls, and curated practice problems.
Arrays & Strings (6)
Two Pointers
O(n) pair/partition via opposing or same-direction indices. Includes Fast & Slow (Floyd's cycle detection).
Sliding Window
Contiguous window with expand-right / shrink-left. Both fixed-size and variable-size.
Prefix Sums & Difference Arrays
O(1) range queries (prefix sum) and O(1) range updates (difference array).
Binary Search
Sorted array, monotonic predicate, or binary-search-on-answer.
Hashing
Frequency counts, seen-state, group-by. When O(1) lookup unlocks the algorithm.
Intervals & Greedy
Sort by custom key, then sweep. Covers most 'interval' and many 'greedy' problems.
Stacks & Queues (1)
Linked List (1)
Trees (3)
Binary Tree Traversals
Pre/in/post-order DFS + BFS level-order. When to use which.
BST Properties
Exploit left < root < right for O(h) ops. In-order = sorted.
Trie (Prefix Tree)
Character-branching tree for O(length) prefix operations.
Graphs (4)
DFS / BFS / Islands
Generic graph traversal + 2D grid flood fill.
Topological Sort
DAG ordering via Kahn's BFS or DFS post-order. Detects cycles in directed graphs.
Union-Find (DSU)
Path compression + union by rank. Dynamic connectivity and Kruskal's MST.
Shortest Paths
Dijkstra (heap, non-negative weights). Bellman-Ford for negative edges.
Heaps (1)
Recursion & Search (2)
Backtracking
Choose → recurse → unchoose with pruning. Subsets, permutations, combinations, N-Queens.
Cyclic Sort
When array contains 1..n: swap each value to its index. O(n) / O(1).
Dynamic Programming (6)
DP — Linear / 1D
dp[i] from constant previous indices. Climbing Stairs, House Robber, LIS.
DP — 2D Grid / Two-Sequence
dp[i][j] over a matrix or pair of sequences. LCS, edit distance.
DP — Knapsack Family
0/1, unbounded, subset-sum, coin change.
DP — Intervals / Partition / MCM
dp[i][j] by trying every split k.
DP — Tree DP
Post-order DP where child results compose into parent.
DP — Bitmask
Use bits as set-of-used. dp[mask] over 2^n states.
Bit Tricks (1)
Finished reading?
Mark it done to track your progress in Interview.