All 29 DSA Patterns
Browse every pattern by category. 29 patterns have free interactive animated walkthroughs.
Array & String
Two Pointers
AnimatedUse two pointers that move toward each other or in the same direction to efficiently search or compare elements in a sorted array or string.
Sliding Window
AnimatedMaintain a window of elements that slides across the array, expanding or shrinking to find optimal subarrays or substrings.
Prefix Sum
AnimatedPrecompute cumulative sums to answer range sum queries in O(1) time after O(n) preprocessing.
Kadane's Algorithm
AnimatedTrack the maximum subarray sum ending at each position, resetting when the running sum becomes negative.
Cyclic Sort
AnimatedPlace each number at its correct index (value i at index i) by swapping, to find missing or duplicate numbers in a range [0, n] or [1, n].
Hashing & Frequency
Sorting & Searching
Binary Search
AnimatedRepeatedly halve the search space to find a target or boundary in O(log n) time.
Merge Intervals
AnimatedSort intervals by start time, then merge overlapping ones by comparing end times.
Bucket Sort / Top-K
AnimatedUse a heap (priority queue) or bucket sort to efficiently find the K largest/smallest/most frequent elements.
Two Heaps
AnimatedUse a max-heap and a min-heap together to efficiently track the median or partition elements into two balanced groups.
K-way Merge
AnimatedMerge K sorted arrays or lists using a min-heap to always pick the globally smallest element across all lists.
Linked List
Tree & Graph
BFS (Level-Order)
AnimatedExplore all nodes at the current depth before moving to the next level, using a queue.
DFS (Pre/In/Post-Order)
AnimatedExplore as deep as possible along each branch before backtracking. Use pre-order, in-order, or post-order depending on when you process the node.
Backtracking
AnimatedBuild solutions incrementally, abandoning a path as soon as it cannot lead to a valid solution.
Topological Sort
AnimatedOrder vertices of a directed acyclic graph (DAG) so every edge goes from earlier to later in the ordering.
Union-Find
AnimatedTrack disjoint sets using parent pointers with path compression and union by rank for near O(1) operations.
Dynamic Programming
0/1 Knapsack
AnimatedChoose items (take or skip each) to maximize value within a capacity constraint.
Unbounded Knapsack
AnimatedLike 0/1 Knapsack, but each item can be used unlimited times.
Fibonacci Pattern
AnimatedEach state depends on a fixed number of previous states, like Fibonacci numbers.
Longest Common Subsequence
AnimatedCompare two sequences and build a 2D DP table where each cell represents the optimal answer for prefixes of both sequences.
DP on Trees
AnimatedApply dynamic programming on tree structures using post-order DFS, where each node's answer depends on its children's answers.
Matrix / Grid DP
AnimatedFill a 2D DP table where each cell represents the optimal answer for reaching that position in a grid, using values from adjacent cells.
Advanced
Monotonic Stack/Queue
AnimatedMaintain a stack or deque where elements are always in sorted order, enabling efficient next-greater/smaller element queries.
Trie
AnimatedA tree-like data structure where each node represents a character and paths from root to nodes form prefixes. Tries enable O(m) insert, search, and prefix queries (m = word length), making them ideal for dictionaries, autocomplete, spell checking, and word search problems where multiple strings share common prefixes.
Greedy
AnimatedMake the locally optimal choice at each step, trusting that it leads to a globally optimal solution. Greedy works when two properties hold: (1) greedy choice property — a local optimum is part of a global optimum, and (2) optimal substructure — an optimal solution contains optimal solutions to subproblems. Common in scheduling, interval selection, and jump/reachability problems.
Bit Manipulation
AnimatedUse bitwise operations (AND, OR, XOR, shift) for efficient computation on integers.
Want all 29 patterns with animated walkthroughs?
The complete book includes detailed visual walkthroughs, practice problems, and step-by-step solutions for every pattern.
Book Coming Soon ($4.99)