Visualizers
Algorithms click when you can watch them work. Each visualizer precomputes every step so you can play, pause, and step backwards and forwards. Edit the inputs to try your own cases.
Sorting algorithms
Read the topic →Partition around a pivot (last element, Lomuto), then sort both sides. O(n log n) average.
Binary search
Read the topic →Each step compares the middle element and discards half of the remaining range. Switch to “lower bound” to see the lo < hi template that finds the first index where a condition becomes true.
Two pointers (pair sum in a sorted array)
Read the topic →Every move rules out a whole row or column of candidate pairs, so the search takes O(n) instead of O(n²).
Sliding window (longest substring without repeats)
Read the topic →The right edge always moves forward; the left edge moves forward only to restore validity. Both move at most n times → O(n).
Monotonic stack (next greater element)
Read the topic →Indices wait on the stack until a bigger value arrives and answers them. Each index is pushed and popped once → O(n).
Graph search on a grid
Read the topic →Explores in rings of equal distance. Finds the shortest path by number of steps, but ignores terrain cost. Click or drag on the grid to draw walls or mud (cost 5); every edit re-runs the search.
Tree traversals
Read the topic →In-order visits left, root, right. On a BST this yields the values in sorted order. Values are inserted into a binary search tree in the order you type them.
DP table: longest common subsequence
Read the topic →dp[i][j] = LCS length of the first i letters of the row string and the first j letters of the column string. Watch each cell pull from its neighbours, then backtrack to recover the subsequence.
| ∅ | B | D | C | A | B | A | |
|---|---|---|---|---|---|---|---|
| ∅ | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| A | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| B | 0 | 1 | 1 | 1 | 1 | 2 | 2 |
| C | 0 | 1 | 1 | 2 | 2 | 2 | 2 |
| B | 0 | 1 | 1 | 2 | 2 | 3 | 3 |
| D | 0 | 1 | 2 | 2 | 2 | 3 | 3 |
| A | 0 | 1 | 2 | 2 | 3 | 3 | 4 |
| B | 0 | 1 | 2 | 2 | 3 | 4 | 4 |