Computation and cost: What counts as fast
In March 1956, Kurt Gödel wrote a letter to John von Neumann, who was dying of cancer in a Washington hospital. Buried in the condolences is a question. Gödel imagines a machine that, given a mathematical statement and a number , decides whether the statement has a proof of length — and asks how the number of steps the machine needs, call it , has to grow. Brute force gives something like : a proof of length is a string of symbols from some fixed alphabet of characters, and a machine can try every string.
But Gödel saw no reason that had to be optimal, and he saw exactly what was at stake if it wasn’t. If could be brought down to or , he wrote, “the mental work of a mathematician concerning Yes-or-No questions could be completely replaced by a machine” — despite the famous undecidability results, his own included. (Those results forbid a machine that answers every mathematical question; they say nothing against finding proofs of a bounded length quickly, which is a finite (merely enormous) search.) Then he asked von Neumann what he thought, and the question sat unread in the literature for thirty years. It is, almost exactly, the question this book is about: the letter is P vs NP, posed fifteen years before either class had a name.
To even state Gödel’s question precisely, you need three things, and they’re this chapter’s arc:
- A definition of a step — some machine so simple that counting its operations is unambiguous, and an argument that the choice of machine doesn’t matter.
- A definition of cost — how running time is measured as a function of input size, and why the measurement deliberately ignores constants and hardware.
- A definition of fast — the class P, the field’s formalization of “feasible,” along with the caveats about where that formalization creaks.
By the end we’ll also meet the first genuine theorem of the subject (a proof that more time really does buy more power) and see precisely why that theorem, strong as it is, says nothing about the question in Gödel’s letter.
The machine: what a step is
Every programming language you’ve used compiles down to something, and if you keep compiling (through bytecode and below) you eventually want a bottom: a machine so primitive that nobody can argue about what one operation costs. The field’s chosen bottom is the Turing machine : an infinite tape of cells, a read/write head sitting on one cell, and a fixed finite table of rules of the form “in this state, reading this symbol: write that symbol, move one cell left or right, switch to that state.” That’s the entire machine. Here is a complete, running example — a Turing machine that adds 1 to a binary number, using one state and three rules:
Watch what a “step” is: read one cell, consult one rule, write one cell, move one position. A step is local, touching a bounded amount of information — and that locality is the point of the definition. In Chapter 2, the proof that crowns Boolean satisfiability (SAT, the puzzle-problem this book orbits) as its master problem works precisely because each step of any computation is this small.
The immediate objection: your laptop is not a Turing machine. It has random-access memory, registers, a cache hierarchy — surely “number of steps” differs between the models? It does, and the answer is the foundational result that makes complexity theory possible: every reasonable model of computation simulates every other with at most polynomial overhead (call the set of such models the club of reasonable machines). A RAM machine step becomes polynomially many Turing machine steps (the head must walk the tape to reach an address, so the cost grows with the memory in use — but it never explodes). A Python statement becomes a bounded pile of RAM operations. And so on around the club: an algorithm taking time on your laptop takes time at most, say, on a Turing machine — never .
One piece of fine print, which will matter in Part III: the equivalences are free only at this coarse resolution. Price them finely and the models genuinely disagree; a one-tape Turing machine provably needs steps to recognize palindromes that a two-tape variant (one extra tape, one extra head) handles in linear time. The Church–Turing thesis says all the machines agree about what can be computed. Complexity theory is the discovery that they never stop arguing about how much, and the arguments are where the field’s few unconditional theorems come from.
This is why the definitions coming next are phrased to be blind to polynomial differences: any finer distinction than “polynomial vs not” would depend on which machine you bought. The claim that this club contains every physically buildable computer — that nothing in nature computes with super-polynomial advantage over a Turing machine — is called the extended Church–Turing thesis , and one caveat right away: quantum computers seriously challenge it. A quantum computer appears to factor integers exponentially faster than any known classical method. What that does and doesn’t mean for this book’s question gets treated properly in Chapter 3; until then, “computer” means anything in the club.
The cost: counting steps
Fix a problem — say, multiplying two numbers. An algorithm’s running time is a function: for each input size (measured in bits, or digits, or any polynomially-equivalent unit), report the number of steps on the worst input of that size:
Why worst case, rather than average? Partly because it’s the only definition that doesn’t force you to choose a probability distribution over inputs (average over what? — the inputs your users send are not uniform random bits). Partly because a worst-case guarantee is what an adversary can’t break, which is what cryptography (Chapter 3) and verification (Chapter 4) need. It’s a genuinely consequential choice, and it has a sting in its tail: a problem can be worst-case hard while almost every instance you’d ever meet is easy. That gap (worst case versus typical case) becomes the central plot of Part II, and it was baked in on page one.
With worst case fixed, we blur the measurement on purpose — twice. The first blur: report up to constant factors and lower-order terms — rather than steps — because constants are what chip speed and implementation details scramble (a 2× faster core halves every count), so keeping them would mean measuring your hardware rather than your algorithm. The second blur, coarser, comes with the next section’s definition: caring only about polynomial versus not, which is what absorbs the machine club’s polynomial simulation overheads. What survives both blurs is the growth rate, and the growth rate is what decides everything:
The chart’s y-axis is logarithmic (each gridline is a leap by orders of magnitude — the only way to fit these numbers in one picture). At , one operation per nanosecond throughout: an algorithm finishes in 10 microseconds, in a millisecond, and needs operations, which is years — about 2,900 times the age of the universe. Exponentials compound mercilessly: moving from to leaves at 90 microseconds while goes from “thousands of universe-lifetimes” to years. No conceivable hardware rescues this. Throw a billion-core datacenter at and you’ve bought yourself 30 more points of , because : the boundary between polynomial and exponential moves by addition when your budget moves by multiplication.
Make it concrete with the two problems that will haunt this entire book. Multiplying two 300-digit numbers by the grade-school method costs about digit-operations — 90 microseconds. Now reverse it: given the 600-digit product of two secret 300-digit primes, find the factors. Trial division has candidates to check. The best algorithm known to science, the general number field sieve , would need roughly operations on a number that size (roughly 2,000 bits — the estimate is the number field sieve’s sub-exponential running-time formula evaluated there, about ), or five billion billion years at our one-op-per-nanosecond rate. The forward direction is homework; the reverse direction is the security assumption underneath TLS. Same numbers, same arithmetic, and an asymmetry of thirty orders of magnitude ( operations against ) that nobody has ever proven necessary.
Why decision problems — doesn’t “find the factors” ask for an answer, not a yes/no?
Complexity theory standardizes on decision problems — questions with yes/no answers, like “does have a prime factor smaller than ?” — because they’re the cleanest to compare, and because almost nothing is lost. With that yes/no question answered for varying , binary search recovers the smallest factor, and repetition recovers the whole factorization — all with polynomially many calls. The general trick (using a decision oracle to construct a solution) is called self-reducibility, and Chapter 3 will run it with real numbers on this book’s running example. A set of inputs whose answer is “yes” is called a language, which is the word you’ll see in the literature; “decide the language” means “compute the yes/no function.”
The class P: a definition of feasible
P (polynomial time) is the class of decision problems — yes/no questions, per the accordion above — solvable by an algorithm whose running time is bounded by some polynomial:
for some constants and that may depend on the problem but not on the input. Multiplication is in P ( by grade school; by the current record ). Sorting, shortest paths, matrix inversion, linear programming, primality testing (a famous late arrival — Chapter 3 tells that story): all in P.
Identifying “polynomial” with “feasible” is called the Cobham–Edmonds thesis , after the two people who proposed it independently around 1965. Jack Edmonds’ version, in his paper Paths, Trees, and Flowers , is worth reading in the original: he calls polynomial-time procedures “good algorithms,” and defends the definition against exactly the objection you’re forming. Why should count as feasible and as infeasible, when for realistic the latter is faster? Three answers, in increasing order of importance:
- Robustness. Polynomials are what survive the machine club’s simulation overheads. “Runs in ” is a statement about your computer; “runs in polynomial time” is a statement about the problem.
- Composition. Polynomials are closed under the things programmers do: call a polynomial subroutine polynomially many times, feed one polynomial algorithm’s output (itself at most polynomially large) into another — the result is still polynomial. Feasibility that didn’t survive function composition would be useless as a theory.
- Empirics. The thesis could have failed in practice, and mostly hasn’t: natural problems in P overwhelmingly turn out to have small exponents ( and better) once anyone cares enough to optimize. Exponents like 100 show up in first proofs, then collapse. There are real exceptions (“galactic algorithms ” whose polynomial superiority only bites at absurd — the multiplication above is one), and a fair scorecard records them. But the pattern is strong enough to bet on, and the field bet on it.
The right mental model for P is not “fast” but closed under being an engineer: within P, effort buys progress (profile, restructure, divide-and-conquer, buy a bigger machine) and the problem yields. Outside it, as the chart above showed, effort is a rounding error on the exponent.
Doesn’t randomness change the picture — half my favorite algorithms flip coins?
There’s a class for that: BPP, problems solvable in polynomial time by algorithms allowed to flip coins and be wrong with probability at most ⅓ (repetition drives the error below any threshold you like — repetitions shrink it exponentially in ). For decades randomness looked like genuine extra power — primality testing was the poster child, solvable fast with coins before anyone could do it without. Then AKS derandomized primality in 2002, and the modern consensus, for deep reasons connected to Chapter 12’s pseudorandomness, is that P = BPP: randomness buys convenience rather than power. This book will mostly say “P” and mean “P, and we’re not worried about coins.” Quantum (BQP) is the exception that genuinely might not collapse, and it waits for Chapter 3.
What we can already prove — and the exact spot where we can’t
A reasonable fear at this point: maybe questions like “does this problem require exponential time” are simply beyond mathematics — maybe nothing of the kind has ever been proven. The fear is wrong, and seeing why sharpens where the real difficulty lives.
In 1965, Juris Hartmanis and Richard Stearns proved the time hierarchy theorem : given meaningfully more time, a Turing machine can decide strictly more problems. There are problems solvable in time that provably cannot be solved in time ; problems solvable in that provably cannot be solved in any polynomial. In particular:
— a genuine, unconditional separation, proven by a technique called diagonalization: roughly, build a problem whose answers are defined to disagree with every fast machine, one machine at a time. (The technique’s anatomy, its successes, and the precise reason it cannot settle P vs NP get a full chapter — Chapter 11.) So complexity theory can absolutely prove impossibility results.
The hierarchy theorem, though, separates classes defined by the same resource at different scales — time from time , polynomial from exponential. Gödel’s question lives elsewhere. His proof-finding problem, the factoring asymmetry above, and the master problem of the next chapter all have the same two-sided shape: brute-force search solves them in exponential time (they sit inside EXP), and checking a proposed answer is easy (multiply the factors back; verify the proof line by line). The question is whether that checkability can be exploited to avoid the search. That question is about a different kind of resource than time-versus-more-time — and on it, the hierarchy theorem and its diagonalization are, as Chapter 11 will make precise, structurally silent.
Look again at what multiplication-vs-factoring actually shows: a problem where finding an answer seems to cost exponentially more than checking one. Checking a factorization: 90 microseconds. Finding it: five billion billion years, as far as anyone knows. Every hard problem you’ve ever cursed at has this flavor — the sudoku that’s obvious to verify, the proof that’s easy to referee. There is a name for the class of problems whose answers are easy to check (that class is NP — Chapter 2 explains the odd name), a single problem that turns out to sit at the top of all of them, and a 1971 theorem that earns it the rest of this book. That’s Chapter 2.
Further reading
- Gödel’s 1956 letter to von Neumann — the full translation; two pages of P vs NP before P or NP existed, and the namesake of Lipton’s blog “Gödel’s Lost Letter.”
- Paths, Trees, and Flowers (Edmonds, 1965) — where “good algorithm” was defined and defended; the philosophical section still reads fresh.
- On the Computational Complexity of Algorithms (Hartmanis & Stearns, 1965) — the paper that founded complexity theory and proved the time hierarchy theorem; its authors won the Turing Award for this work.
- P =? NP (Aaronson, 2016) — the survey this book is, in many ways, a long on-ramp to; skim it now, reread it after Chapter 14.
- Introduction to the Theory of Computation (Sipser) — if you want the Turing machine formalities done properly; Chapters 7–9 cover this book’s Part I with full proofs.