Algorithms

Study notes for contest and interview algorithms, starting from one map.

This section follows my second pass through algorithms: partly for the coding rounds of HFT and tech interviews, partly for contests, where the mathematics problems in the second half of a contest are mine. Start with the map; each block gets a post here once it is covered.

The map: what to learn, in what order

Algorithm map: a green top band of interview basics to write right and fast; a grey middle band of topics to skim, knowing what they solve and when to reach for them; and three lanes of contest mathematics at the bottom: number theory from fast power, inverses and sieves to Möbius inversion and Du's sieve, counting from binomials mod p, inclusion-exclusion and binomial inversion to generating functions and NTT, and linear algebra from matrix fast power and Gaussian elimination to determinants and the matrix-tree theorem.

Click the map for the interactive version: click a box to see what it solves and when to reach for it; the buttons above it step through learning routes.

Posts 6 min read

A1: Complexity, Binary Search, Two Pointers, Prefix Sums

All four topics in this round answer queries on an array, and all of them bring brute-force $O(n^2)$ down. Two properties make that possible: monotonicity (binary search, two pointers) and accumulated quantities that can be …

Posts 18 min read

C0: Mathematics in Contests

In the mathematics problems of the second half of a contest, the hard part is rarely the theorem itself. Most theorems can be memorised; what goes wrong is not seeing which one a problem needs, or seeing it and failing to derive a …

Posts 13 min read

L2: XOR Basis

Given $n$ numbers, pick any subset and XOR it together: what is the largest result? With $n = 50$ there are $2^{50}$ subsets, too many to enumerate. But the subset XORs repeat a lot. With three numbers $a$, $b$, $a \oplus b$, the …