













Two
Pointers
Two indices moving over the same sequence to maintain an invariant — converging, fast/slow, sliding window.
converging · fast-slow · sliding
Binary Search
Variants
Boundary conditions are the field's largest unsolved teaching problem.
3 variants · O(log n)
Backtracking
Decision-tree expansion — uniquely suited to animation.
branching state machine
Monotonic
Stack
Stack-state transitions are invisible in code, dramatic in animation. The stack is the protagonist.
next-greater · histogram
BFS / DFS on Gr
DFS
A queue gives breadth, a stack gives depth — same algorithm, two traversal orders.
queue · stack · flood fill
Heap &
Priority Queue
Cheap access to the extreme — min or max — while everything else stays loosely ordered. A family of three sub-patterns: top-k, two heaps, k-way merge.
top-k · two-heaps · k-way-merge
Tree
Traversal
Every traversal visits every node once — only when relative to children's recursion differs.
preorder · inorder · postorder · level
Linked List
Manipulation
Three pointers — prev, curr, next — let you rewrite a list in place without losing the tail.
reverse · merge · reorder
Dynamic
Programming
A table fills itself, one cell at a time — each entry composed from a constant number of earlier ones. A family of seven sub-patterns.
1-d · 2-d · knapsack · interval · state-machine · tree · bitmask
Union
Find
Maintain a partition of N elements into disjoint components — merge two components in near-constant time, with the forest flattening itself on every query.
connected components · O(α(N))
Trie
Store a set of strings on a tree of characters — words that share a prefix share a path, and a single 'end-of-word' flag separates stored words from in-flight prefixes.
prefix queries · autocomplete · word-search
Topological
Sort
Linearize a directed acyclic graph so every edge points left-to-right — each node enters the order only after every prerequisite has already left.
Kahn's algorithm · O(V + E) · cycle detection
Prefix
Sum
Pay O(N) once to amortize every range query to O(1) — and flip it inside-out for cheap range updates. A family of four sub-patterns.
1-d · 2-d · difference · hash-map
Shortest
Path
Find the shortest route from a source — the mechanism splits by what the edges carry. BFS for uniform costs, Dijkstra for non-negative, Bellman-Ford for negatives, Floyd-Warshall for all pairs.
BFS · Dijkstra · Bellman-Ford · Floyd-Warshall
Merge
Intervals
Sort by start, then sweep — each interval either extends the current merge or commits it and starts a new one. The whole pattern lives in that one comparison.
sort + linear sweep · O(N log N)
Bit
Manipulation
Treat integers as their bits, not their values — XOR a number against itself to zero it, against zero to keep it. The trick is recognizing when a problem has a hidden bit-level structure.
XOR · bit mask · O(N)
Cyclic
Sort
When values live in [0, N] or [1, N], the index IS the pointer — swap to home or sign-flip to mark seen. Missing/duplicate problems collapse to O(N) time, O(1) space.
index-as-pointer · O(N)
Sweep
Line
Turn each interval into a +1 event at its start and a −1 event at its end, sort by position, then sweep. The running active count rises and falls — its peak is the answer for max-concurrent problems.
endpoint events · running max · O(N log N)
Greedy
At every step, take the locally optimal commit — and prove it never gets undone. No backtracking, no DP table.
interval-scheduling · jump-game · gas-station
Segment
Tree
A balanced binary tree whose nodes hold range aggregates. Any range decomposes into O(log N) canonical pieces — so queries and point updates are both O(log N).
range query · point update · O(log N)
Fenwick
Tree
An implicit tree via the lowest set bit — O(log N) point updates and prefix sums in ten lines of code, no nodes to allocate.
implicit tree · lowbit · O(log N)
String
Matching
Find P inside T in O(N + M) instead of O(N·M). Three sub-patterns differ only in what they precompute from the pattern: failure function, rolling hash, or Z-array.
kmp · rabin-karp · z-algorithm
Matrix
A 2-D coordinate space with two indices. The trick is the walk order — transpose+reverse, perimeter shrink, or monotone-corner staircase.
rotate · spiral · staircase-search
Math &
Number Theory
Recognize the number-theoretic structure (divisibility, modular, multiplicative) and an O(N) loop collapses to O(log N) or O(N log log N).
gcd-lcm · modular-power · prime-sieve
Minimum
Spanning Tree
Cheapest way to connect every node of a weighted graph — exactly N−1 edges, no cycles, minimum total weight.
kruskal · prim
Cache
Eviction
Fixed-capacity store with O(1) get and put. Every eviction policy is a different answer to "which entry do I drop when full?"
lru · lfu · O(1) get/put
Monotonic
Deque
Two ends, two jobs — front evicts when the window slides past, back drops what's dominated. The front is always the window's max in O(1).
sliding-window max · O(N)
Bidirectional
BFS
Run BFS from both endpoints; meet in the middle. Cuts shortest-path search from O(b^d) to O(b^(d/2)) when both source and target are known.
meet-in-the-middle · O(b^(d/2))
Linear Algebra
Primerarticle
The minimum linear algebra you need before any Transformer diagram — vectors, dot products, matrix multiplication, cosine similarity, norm, transpose. Visual and short.
9 topics · ~55 steps · beginner-friendly
Transformer
Forward Passcoming soon
Walk one prompt all the way through a modern LLM — tokenize, encode position, attend, decode the next token, cache for reuse. Five ordered stages, each its own pattern.
tokenize · encode · attend · decode · cache
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。