NP and the master problem: One problem to rule them all
On May 4, 1971, at a computing conference in Shaker Heights, Ohio, a University of Toronto professor named Stephen Cook presented a paper with the unassuming title The Complexity of Theorem-Proving Procedures . In it, he proved that one specific problem (Boolean satisfiability) stands apart: every problem whose solutions can be efficiently checked can be mechanically translated into it. Crack that one problem and you crack them all. Across the Iron Curtain, a Soviet mathematician named Leonid Levin proved the same thing independently (publication was delayed until 1973 , and the Soviet literature had been circling the theme for years under the name perebor — “brute-force search”). The next year, Richard Karp showed the result wasn’t a curiosity about one problem: 21 problems that operations researchers had been beating their heads against for decades (scheduling, packing, routing, coloring) all turned out to be the same problem in different clothes. This chapter is about that discovery:
- We name the pattern from Chapter 1’s cliffhanger: problems whose answers are easy to check. That’s the class NP, defined by certificates and verifiers.
- We meet SAT, the satisfiability problem, and build this book’s running example — a six-clause formula you can solve by hand, whose descendants with a million clauses will be solved by industrial tools in Chapter 4.
- We prove (at engineer’s rigor) the Cook–Levin theorem (SAT is NP-complete, the universal problem) and then walk the razor-thin boundary where SAT variants fall back into P.
By the end, “P vs NP” will be a precise question about one concrete problem: is there a polynomial-time algorithm for SAT?
NP: the class of checkable problems
Chapter 1 ended with an asymmetry: finding the factors of a 600-digit number seems to take geological time, but checking a claimed factorization takes 90 microseconds. The sudoku you struggle with, you grade in seconds. A flight itinerary under $800 with no overnight layovers may take an evening to find, but your friend’s claimed itinerary takes a minute to audit. In each case, a solution comes with something you can hand to a skeptic — a certificate (also called a witness) — that makes verification cheap even when discovery was expensive. (Formally we mean each problem’s decision version, Chapter 1’s yes/no framing: “is there an itinerary under 800 dollars?” rather than “find one.” A decision problem asks for a single bit.)
NP is the class of decision problems with that shape: whenever the answer is “yes,” there exists a certificate, of at most polynomial size, that a polynomial-time verifier can check.
Here is the problem instance, the set of all yes-instances (a “language,” in Chapter 1’s jargon — a decision problem is such a set), and the instance’s size in bits. Read the definition with an engineer’s suspicion, because three traps lurk in it:
- The certificate only needs to exist. Nobody has to be able to find it efficiently — existence is the whole definition. NP is not “hard problems”; it’s “checkable problems.”
- “No” is unprotected. The definition demands certificates for yes-answers only. For “this formula has no solution,” no short evidence is promised — an asymmetry that opens Chapter 3.
- The name is a historical accident. NP stands for nondeterministic polynomial — in the original formulation, a machine that can guess the certificate and verify it. It does not mean “not polynomial.” P ⊆ NP trivially: if you can solve a problem outright, you can verify a yes-answer by ignoring the certificate and solving it. (So P vs NP asks whether the containment is strict.)
And one bound in the other direction, cashing in Chapter 1: every NP problem is solvable in exponential time — enumerate all possible certificates and run the verifier on each. So NP lives between P (Chapter 1’s polynomial-time class) and EXP (exponential time — the class Chapter 1 proved strictly bigger than P), precisely in the gap where the hierarchy theorem went silent: that theorem separates less time from more time, and checking-versus-finding is not a time-scale question. In 2000, the Clay Mathematics Institute put a million-dollar bounty on determining where in the gap NP actually sits.
SAT: the master problem
Now the problem Cook chose. A Boolean formula is built from variables that take values true/false. A literal is a variable or its negation ( or ). A clause is an OR of literals. A formula in conjunctive normal form (CNF) is an AND of clauses. SAT asks: given a CNF formula, does any assignment of true/false to the variables satisfy every clause? (3-SAT is the special case where every clause has at most three literals.)
That’s dry, so here’s the same thing with people in it — the formula this book will carry from here through Chapter 10. You’re planning a dinner party with four possible guests: alice, bob, carol, dave. House rules: at least one of Alice, Bob, Carol must come. Alice and Bob are feuding, and so are Bob and Carol. Carol and Dave are a couple who only come together. And Alice won’t share a room with Dave. As a CNF formula:
Every constraint-shaped thought becomes clauses this way. “At least one” is a clause of positive literals. “Not both” is a clause of two negative literals. “If then ” is — verify it by checking that the one assignment breaking the implication ( true, false) is exactly the one falsifying the clause. Try the formula yourself — find all three satisfying assignments:
Solve it by hand once, because the reasoning you just did is Chapter 4 in miniature: if Carol comes, Dave must come (clause 4), but then Alice can’t (clause 6), and Bob can’t anyway (clause 3)… — you were propagating forced consequences of a guess. Hold the formula’s answer in your head: exactly three of sixteen assignments work: , , — each set naming the guests invited (the variables set true).
Those sixteen assignments also have a geometry. Give each guest an axis: an assignment is then a corner of a 4-dimensional cube, and two corners share an edge exactly when they differ in one guest. This is the Hamming cube (and Hamming distance counts the differing coordinates). The search space is a terrain:
Every algorithm this book will meet is a strategy for exploring this cube: flipping one variable is walking an edge, fixing a partial guest list is selecting a sub-cube, and the solutions form a sub-territory whose shape — scattered? clustered? connected? — turns out to govern how findable they are. Even in our toy, the three solutions are no one’s neighbors: pairwise Hamming distances 2, 3, and 3. At the cube has corners, and the geometry of the solution territory becomes a serious scientific question. Chapter 6 maps it, with help from physicists.
And if you flatten the cube onto a line, failing assignments become wave interference?
They do. Fix a variable order — say first, last — and read each assignment as a binary number (): the cube’s 16 corners become positions 0 through 15 on a line, and each variable becomes a square wave. The slow wave is false for the whole left half and true for the whole right; , the fast wave, alternates every step. A clause fails only on the intersection of its literals’ half-periods, so each clause’s failing set is a periodic comb — and a -literal clause’s comb covers exactly of the line — positions, arranged in a pattern set by which frequencies it mentions (fast variables space the teeth finely; slow ones fuse them into blocks). Here is the dinner party, computed:
Satisfiability is now an interference question: the formula is unsatisfiable exactly when the clauses’ combs superpose to cover every position — and a satisfying assignment is a surviving gap in the interference pattern. The picture pays off twice later. The coverage is why a random assignment satisfies ⅞ of random 3-clauses: the number behind Chapter 9’s hardness-of-approximation floor. And the rigorous version of “variables as frequencies” is the Walsh–Hadamard (Fourier) basis of Boolean functions: Chapter 7’s parity bound has a Fourier reading (shallow circuits are provably “low-frequency” objects, a theorem of Linial, Mansour and Nisan, and parity — the product of all the waves — is the purest high-frequency signal, which is exactly why they can’t compute it), and the analysis behind the ⅞ theorem is Fourier analysis outright. One caveat: for deciding a given formula, no one knows how to cash the wave picture faster than brute force — superposing combs over positions is just the truth table again. It’s a lens, not an algorithm; but it’s the lens the field’s sharpest tools are ground from.
SAT is in NP by inspection — a satisfying assignment is the certificate, and the verifier is one pass over the clauses:
Checking: with clauses of at most literals, verification is — for our formula, six looks at at most three literals each. Finding: nothing obvious beats trying assignments, and assignments double per variable — 16 for our four guests, for sixty. SAT is checkable in linear time and searchable, naively, in exponential time. The whole question is whether the naivety is necessary.
Hold on — “exponential” in what? The formula’s length and its variable count are different numbers…
Caught — and the gap between those two numbers is where SAT’s difficulty actually lives. Call the formula’s text length and its variable count . Brute force costs — so if a formula is at least as long as its own truth table (), brute force is : polynomial in the input. SAT over fully-spelled-out constraint tables is easy; writing the question down already did the exponential work. And spelling-out is the common case in function-space: almost every function of variables requires a description of length about (a counting argument, delivered in Chapter 7 — a typical function simply has no shorter name than its full table).
So NP-hardness lives entirely in the opposite corner: formulas whose meaning (a constraint over rows) is exponentially larger than their text. A CNF formula is, seen this way, a compression format, and SAT is the problem of reasoning about compressed data without decompressing it. (For 3-CNF the compression is mandatory: there are only distinct 3-clauses over variables, so after deduplication every 3-SAT instance has length polynomial in its variable count.) The hard instances of this book all sit at high meaning-density: the Cook–Levin formula below packs an entire machine-run’s validity into polynomial clauses; Chapter 6’s hard random formulas keep at a fixed fraction of , the maximally-compressed regime (where the modern Exponential Time Hypothesis (Chapter 13) conjectures nothing beats ).
The frame recurs. Chapter 5’s OBDDs (ordered binary decision diagrams) attack SAT by deliberately decompressing: pay the exponential once, then every query is cheap — and the payment explodes exactly for the functions that resist compression. And in Chapter 13, turning the dial one level further — the formula itself handed over compressed, as a small circuit describing an exponentially long formula — jumps satisfiability from NP-complete to NEXP-complete. Difficulty, throughout, is a property not of questions but of the gap between a question’s size and its meaning’s size. (One warning against reading “compressible” as “simple”: the Cook–Levin theorem below shows these short formulas contain universal computation — every checkable question in mathematics compiles into them. Rare by counting, and rich enough to hide everything this book is about.)
Reductions: how problems compare
Before Cook’s theorem can even be stated, we need the tool it’s made of. A (polynomial-time) reduction from problem to problem is an efficient translator: a polynomial-time function that converts any instance of into an instance of with the same answer.
If such a translator exists, then an algorithm for solves too — run the translator, then the -solver. Read as ” compiles to ,” or ” is at least as hard as .” For an engineer this is the most familiar idea in the book wearing formal dress: you reduce every problem to SQL, to regex, to an integer-linear-programming (ILP) solver, to sort | uniq -c. Complexity theory just insists the compiler itself be cheap, so it can’t smuggle in the hard work.
Here’s a real one, small enough to verify by hand: every CNF formula reduces to 3-SAT. The only obstacle is long clauses, and they split. A five-literal clause becomes three 3-literal clauses with two fresh variables chaining them:
If some is true, set the ‘s before it true and after it false, and all three clauses check out; if all are false, the clauses force true, then true, and the last clause dies. (We verified the equivalence by brute force over all 32 assignments of the — it holds.) In general a -literal clause becomes clauses with new variables: the blowup is linear, the translator is a loop. This is what reductions look like up close — gadgets: little widgets of structure in the target problem that simulate the source problem’s parts.
One more property: reductions compose. If and then — polynomials closed under composition again (Chapter 1 keeps cashing checks). So “reduces to” organizes all of NP into a hierarchy of hardness. Cook’s question was: does the hierarchy have a top?
Cook–Levin: SAT is universal
The theorem: every problem in NP reduces to SAT. A problem with this property (in NP, and every NP problem reduces to it) is called NP-complete: the “complete” means it contains the full difficulty of the entire class. Solve SAT in polynomial time and every checkable problem collapses into P — Gödel’s dream of mechanized proof-finding, from Chapter 1’s letter, included; prove SAT needs super-polynomial time and P ≠ NP. SAT is not a hard problem; it is, in a precise sense, the hard problem.
At first the claim sounds impossible to prove — how do you reduce every NP problem, including ones nobody has invented yet, to one formula? The proof is one of those arguments that looks like a magic trick until you see that it only uses facts already on our table. Any NP problem has a verifier — a machine. Machines can be filmed: write down the complete configuration (tape, head, state) at every step, row after row, and you get a rectangular grid called a tableau — polynomially many rows (the verifier is poly-time) by polynomially many columns (it can only touch polynomially many cells). The input and a blank slot for the certificate fill the top row; “accept” appears somewhere in the bottom row if and only if some certificate works.
Now the only idea in the proof: because a Turing machine step is local (Chapter 1’s load-bearing fact) the grid is a valid film if and only if every little 2×3 window of cells is consistent with the machine’s rule table (Chapter 1’s finite instruction list). Why 2×3 is enough: one step changes one row into the next, and it can only touch the head’s cell and its immediate neighbors — so two consecutive rows, three adjacent columns, capture everything a step can do. Correct computation, a global property, has shattered into polynomially many constant-size facts. And constant-size facts about a handful of true/false cell-variables are exactly what CNF clauses express — the general recipe: list the window’s forbidden combinations and veto each with one clause, the dinner party’s “not both” pattern scaled up:
So: one variable per possible symbol per cell, a constant batch of clauses per window, clauses pinning row 0 to the input (with the certificate cells left free), one clause demanding the accept state. The resulting formula is polynomially large, built by an utterly mechanical translator, and satisfiable precisely when some certificate makes the verifier accept. Every NP problem just compiled to SAT. ∎
Notice what the proof did not use: nothing about the problem being reduced — only that it had a verifier. That’s why one theorem covers problems not yet invented. And notice the aftermath, which is where Karp comes in: to prove some other problem NP-complete, you no longer need Cook’s machinery — show is in NP, and reduce SAT (or any known NP-complete problem) to ; composition does the rest. That’s how 21 problems fell in 1972, and how thousands have fallen since: clique, graph coloring, traveling salesman, subset-sum, bin packing, generalized sudoku, protein structure models, most scheduling, Minesweeper. Every one of them is SAT in costume; every one of them, fed to the translator, becomes clauses. (This is Chapter 4’s business model. A 9×9 sudoku becomes 729 variables (one per cell–digit pair, ) and 11,745 clauses under the standard encoding: 81 “this cell holds some digit” clauses, plus pairwise “these two can’t both be true” clauses — for cells: 81 cells × digit pairs , and rows, columns, and boxes each happen to total the same. A SAT solver eats it in milliseconds.)
What does an NP-completeness proof buy you, practically, as an engineer?
Permission to stop looking for the clean polynomial algorithm, and guidance on what to do instead. When your problem is NP-complete: (1) stop burning weeks hunting an exact fast algorithm that would, incidentally, collect a million dollars; (2) your options become approximation, heuristics, special-case structure, or small — and, surprisingly often, (3) encode it to SAT and use an industrial solver, because Chapter 4’s engines routinely crush structured million-variable instances despite worst-case theory. NP-completeness is a statement about the worst case of the general problem — not a curse on your particular instances. The gap between those two statements is Part II of this book.
The razor’s edge: where SAT falls back into P
A fair first instinct is that hardness comes from scale — many variables, many clauses. The truth is stranger: hardness is a structural property of the constraint type, with a boundary so sharp it looks like a typo.
- 2-SAT (every clause at most two literals) is solvable in linear time. A 2-clause is two implications ( means and ); build the implication graph (a node per literal, an edge per implication), and the formula is unsatisfiable exactly when some variable and its negation sit in the same strongly connected component — because that means forces and forces , a contradiction either way. Three literals: NP-complete. Two: a
tarjan()call. - Horn-SAT (at most one positive literal per clause — the shape of logic-programming rules: “if and then ”) is solvable in linear time by unit propagation, the same forced-consequence reasoning you did at the dinner party. It works because a violated Horn clause forces its one repair, while a violated 3-clause offers a menu of three. Branching factor one versus three — the whole dichotomy in miniature. And forcing is no toy: a circuit gate (” fires if and fired”) is a Horn clause, so propagation cascades simulate any polynomial-time computation — Horn-SAT is P-complete under log-space reductions (poly-time reductions would make the label vacuous), as hard as tractable gets.
- XOR-SAT — clauses are exclusive-ors instead of ors (“an odd number of these literals is true”) — solvable in polynomial time, because XOR-clauses are linear equations over the field of two elements, and Gaussian elimination doesn’t care that the field is tiny. Stare at an XOR-SAT instance and it looks every bit as scrambled and combinatorial as 3-SAT. It isn’t, and when someone announces a P ≠ NP proof, XOR-SAT is often the first counterexample referees reach for — Chapter 13 tells the famous story.
You might expect, between the easy variants and the complete ones, a smooth gradient of intermediate difficulty. There isn’t. Schaefer’s dichotomy theorem (1978) proves that every SAT-like constraint language — a fixed menu of allowed clause shapes, like “2-literal clauses only” or “XORs only” — is either in P or NP-complete. For this entire family of problems, the middle is empty. (Whether any NP problem can live strictly between P and NP-complete is a subtler question; the next chapter answers it.)
The islands are also easy in two different ways. 2-SAT and Horn run on propagation: monotone forcing that only ever adds conclusions. XOR-SAT runs on cancellation: Gaussian elimination subtracts equations until terms annihilate, and nothing in a forcing cascade can un-assert anything. The split is a theorem twice over. Barto and Kozik proved that a constraint problem is solvable by local propagation (of any fixed radius) precisely when it cannot encode linear equations; parity is invisible to every bounded window. And the full CSP (constraint satisfaction problem) dichotomy (Schaefer lifted to arbitrary finite domains, conjectured in 1993, proved independently by Bulatov and Zhuk in 2017) says every such problem is in P or NP-complete, with every tractable one solved by interleaving exactly these two moves: accumulate or cancel.
One more twist, checkable by sorting. Classify any 3-clause by sign pattern: two or three positives means at most one negative (dual-Horn); zero or one positive means Horn. Every case is covered, so every 3-SAT formula is the conjunction of one Horn formula and one dual-Horn formula — two linear-time theories, stapled together. Take , “at most one of the three,” whose solutions are the cube’s bottom (weight, the count of true variables, at most 1), and , “at least two,” whose solutions are the cube’s top. Each half is satisfiable in linear time; the conjunction is unsatisfiable. NP-completeness, on this view, is the price of the handshake between a floor theory and a ceiling theory that share variables.
Is there one statement that unifies all the islands?
Yes, and it is how the dichotomy theorems are actually proved. Each island’s solution set is closed under an operation that combines solutions into new solutions. Horn: the coordinatewise AND of two solutions is a solution (which is why a unique bottom solution exists). 2-SAT: the coordinatewise majority vote of any three solutions is a solution. XOR-SAT: the triple-XOR of three solutions is a solution, because linear equations pass XOR through: . The smallest clause separates the islands: has solutions ; the majority of all three is , a solution, but the AND of and is , which isn’t — so this clause is 2-SAT territory but not, as written, Horn territory. (Flip the sign of and it becomes Horn; Chapter 4 turns that renaming trick into a theorem.)
Operations like these are called polymorphisms, and the dichotomy in its modern form reads: a constraint language is in P exactly when its solutions are closed under some operation of a particular well-behaved kind (a cyclic or weak near-unanimity polymorphism, which AND, majority and triple-XOR all are), and NP-complete otherwise. “Nontrivial” alone isn’t enough: Not-All-Equal 3-SAT is closed under flipping every bit, which is not a dictator (an operation that just copies one input), yet it is NP-complete. The polymorphism even dictates the algorithm: AND-closure gives propagation toward the bottom, majority-closure gives the implication-graph method, XOR-closure gives Gaussian elimination. Hardness, on this view, is the absence of any well-behaved operation under which solutions compose. And the tableau construction above says where that absence comes from. A 3-SAT solution set can be the accepting computation histories of any machine, and machines don’t average: the AND, majority, or XOR of two valid histories is not a valid history. Universality of the syntax and lawlessness of the semantics are one fact, seen from two sides.
One problem now carries the weight of every checkable problem: a polynomial algorithm for SAT would make verification and discovery the same thing. Before asking whether that algorithm exists, you should want to know what hangs on the answer — what certifies a “no,” what lives above NP, and why the RSA keys securing your TLS sessions quietly assume the answer is no. That map is Chapter 3.
Further reading
- The Complexity of Theorem-Proving Procedures (Cook, 1971) — the paper; short, and the tableau proof is recognizably the one above.
- Reducibility Among Combinatorial Problems (Karp, 1972) — the 21 reductions that turned one theorem into a field; skim the tree of reductions on page 98.
- Computers and Intractability: A Guide to the Theory of NP-Completeness (Garey & Johnson, 1979) — the legendary field guide; its appendix of 300+ NP-complete problems is still the first place to look yours up.
- A Personal View of Average-Case Complexity (Impagliazzo, 1995) — read sections 1–2 now for the “five worlds” we visit next chapter.
- The History and Status of the P versus NP Question (Sipser, 1992) — includes the perebor backstory and a translation of Levin’s note.