Algorithm Patterns

The reusable moves behind interview problems — recognize each pattern, run it, and prove why it works.

Scanning & windows

Linear passes that touch each element O(1) times: pointers, windows, prefix sums, and hash lookups.

Search & ordering

Exploit order: halve sorted spaces, keep monotonic stacks, sweep intervals, and track top-k with heaps.

Pointers, tries & bits

Structural moves on linked nodes, prefix trees, and binary representations.

Graph traversal

Visit every node with intent: layer order, depth order, parity, and dependency order.

Connectivity & shortest paths

Merge components with union-find, span them cheaply, and settle shortest distances greedily.

Choices & tables

Commit greedily with proof, backtrack on dead ends, or memoize overlapping subproblems.

Course checkpoint

Choose the invariant and data movement that fit each common problem shape.