Interactive visualizers
138 pages, one house style. Every diagram is driven by a real,
instrumented implementation of the algorithm it’s showing — step through with the
controls or the arrow keys, and the code pane highlights the exact line running at each frame.
← Study library·Pattern 1 — Traversal·Pattern 2 — Tree Recursion·3 — Two Pointers·4 — Sliding Window·5 — Binary Search·6 — Graphs
Pattern 1 — Traversal
Order of visitation is the whole subject: what you see, when you see it, and
what you are allowed to remember. Twenty-two pages.
◆ Depth-first traversals, compared
A Traversal fundamentals
B The level-order family
C The tree as a graph
D N-ary generalizations
E Traversal without a tree
◇ Extra reps
Pattern 2 — Tree Recursion
One skeleton — ask both children, combine, hand the result up — and
twelve mutations of it. What changes between sub-variants is never the traversal; it is
what travels, and in which direction. All 30 pages, grouped as in the bundle.
A Postorder aggregationidentity · combine · own contribution
B Two trees in lockstepthe pairing rule is a parameter
C The record / return splitreturn what composes, record what does not
D State flowing downthe parameter is the state
E Root-to-leaf pathsadd before recursing, remove after
F Prefix sums on the root paththe bridge from arrays to trees
G Lowest common ancestoran overloaded return value
H Construction from traversalsit is always an off-by-one
I Serializationthe null markers are the structure
J Structural rewiringonce you mutate, order is load-bearing
K Multi-dimensional statereturn every case the parent might be in
L Rerooting — two passeswhen every node needs its own answer
Pattern 3 — Two Pointers
Two indices, and an argument for why moving one of them can never skip the answer. 33 pages.
A Converging pointers on sorted datathe discard argument is the whole pattern
B Converging with a discard proofgreedy: prove the smaller side can be dropped
C k-Sum reductionpeel an index, recurse, bottom out at two pointers
D Read/write compactionthe prefix [0, write) is the answer so far
E Two-sequence advancethe whole design question is which pointer moves
F Backward-writing mergewrite from the back and you never clobber
G Fast & slow, and gap pointersdistance, not position
H Partitioningthree regions, one pass
I Expand around center2n−1 centers, not n
J Cyclic sortvalue v belongs at index v−1
K Counting pairs on sorted datacount the block, don't enumerate it
Pattern 4 — Sliding Window
One pass, two boundaries, and an invariant that decides when the window has to give ground. 27 pages.
A Fixed-size windowthe frame never changes size
B Variable window, maximize lengthgrow greedily, shrink only when invalid
C Variable window, minimize lengthshrink as far as it will go, then record
D Non-shrinking windowsthe window slides but never contracts
E Frequency-map matchinga matched counter beats rescanning the map
F Counting windowsa valid window contributes r − l + 1
G At-most-K → exactly-Kexactly(k) = atMost(k) − atMost(k−1)
H Complement / inverse windowsthe ends are not a window, but the middle is
I Monotonic deque windowsthe front is always the answer
K ⚠ Anti-patterns — when the window is illegaleach page runs the naive window until it visibly fails
Pattern 5 — Binary Search
Halve the space each step — on an array, on a rotation, or on the answer itself. Nine pages.
A/B/C Boundaries and the generic predicatelower bound is the one to memorise
D Rotated sorted arraysprove which half is still sorted
E Unimodal / peakcompare against the neighbour, not a target
G Answer space, minimize the maximumsearch the answer, test with a predicate
K Partition binary searchsearch the split, not the value
Pattern 6 — Graphs
The graph is usually implicit — neighbours are computed, never stored — and the
only design decisions are what a node is and what you carry. Twelve pages so far, across all three graph patterns.
A Traversal 1.A — flood fill on a grid
B Traversal 1.B — boundary seeding, invert the question
C Traversal 1.C — grid BFS, unweighted shortest path
D Traversal 1.D — multi-source BFS
I Traversal 1.I — enumerating paths on a DAG
A Ordering 2.A — directed cycle detection, three colours
E Ordering 2.E — union-find, the structure itself
E Weighted 3.E — Bellman–Ford, and where Dijkstra breaks
Also in this folder
Earlier or alternate takes on pages that also appear above, kept because they
are not duplicates — they use a different explanatory framing. Listed here so nothing in the
folder is unreachable.