If the best answer is out of reach, how close can you get? Sometimes arbitrarily close, sometimes not one percent better than guessing. The PCP theorem says why
If finding the best answer is NP-hard, settle for a good one. For some problems a polynomial-time algorithm can get within one percent of the optimum. For others it provably cannot get within a factor of a million, unless P = NP. The line between the two is drawn by one of the deepest theorems in computer science.
Pick a problem and compare a fast algorithm’s answer with the true optimum. Drag the cities, press Play to watch the tour being built, and try “Worst case” on each tab to push the algorithm towards its bound.
Step 26 of 26. Short-cut: skip every city already visited. Straight lines are never longer than detours, so the tour is no longer than the walk.
Drag a city to move it; tap empty space to add one (up to 12, the cap that keeps the exact search instant). Rose dots: the optimal tour, found by exponential search. White: spanning tree. Amber: matching on the odd cities. Indigo arrows: the Euler walk. Sky: the tour the algorithm returns. Lengths are in hundredths of the picture’s height. “Worst case” is a zigzag tuned by search to be bad for both algorithms; the bounds 2 and 1.5 are only approached with many more cities. The matching is found here by exhaustive dynamic programming; the real algorithm uses Edmonds’ polynomial-time matching.
An α-approximation algorithm runs in polynomial time and, on every input, returns a solution within a factor α of the optimum. The difficulty is that the algorithm cannot compute the optimum it is being compared with. Every proof therefore rests on a lower bound for the optimum that the algorithm can see. For the travelling salesman it is the minimum spanning tree: delete one leg of the best tour and a spanning tree remains, so the tree is shorter. Walking round the tree costs twice the tree, and short-cuts never lengthen a walk when distances obey the triangle inequality, which gives a factor 2.
Nicos Christofides (1976), and independently Anatoliy Serdyukov, replaced the doubling by a minimum-weight perfect matching on the tree’s odd-degree vertices. The best tour, short-cut to those vertices, splits into two matchings, so the cheaper one costs at most half the optimum, and the total is at most 3/2. For vertex cover the visible lower bound is a matching: no vertex can cover two of its edges, so taking both ends of a maximal matching is within a factor 2.
For MAX-3SAT a clause on three different variables fails a uniformly random assignment with probability 1/8, so the expected number of satisfied clauses is 7/8 of all of them, and the optimum is at most all of them. David Johnson (1974) removed the coins by the method of conditional expectations: fix one variable at a time, always to the value that keeps the expected count from falling. For set cover the greedy algorithm is within a factor H(k) = 1 + 1/2 + … + 1/k, about ln k, where k is the size of the largest set; here the ratio is not a constant, and the worst-case tab shows it growing.
The demos compare each algorithm with an optimum found by exponential search on a dozen or so items. That checks the guarantees on small cases; the guarantees themselves are theorems, true at every size. See also: The Web of Reductions, where these problems are shown to be one problem in disguise as far as exact solution goes. As the next demo shows, approximation tells them apart.
Tap a bar to see who proved what. Then slide ε to buy accuracy with time on a knapsack, and switch to arbitrary distances to see a claimed ratio turn into a test for Hamiltonian cycles.
A wide unexplained gap: nobody knows where between about 1.008 and 1.5 the truth lies.
The hatched stretch is open: no polynomial-time algorithm is known there, and no proof that none exists.
Tap a problem for its sources. Position along a bar is the guaranteed fraction of the optimum (for a minimisation problem, optimum ÷ guaranteed cost). Sky: reached by a known polynomial-time algorithm. Rose: proved NP-hard to reach, so out of reach unless P = NP. Hatched: unknown. With the conjecture switched on, the paler rose with a dashed edge shows what would also be hard; those stretches are conditional.
Pack the most value into a bag of limited weight. Slide ε down and watch the answer close in on the optimum while the table grows.
14 items; bar height shows value (on a square-root scale, so that small items stay visible), weights are roughly proportional to value, and the number beneath is the rounded value the scheme works with: an item rounded to 0 is invisible to it. Sky: packed by the scheme. Dashed rose outline: in an optimal packing. The exact method is the same dynamic programme on unrounded values; its table grows with the size of the numbers themselves, which is exponential in their number of digits, so it is only affordable here because the values are below 20,000. The scheme’s table has at most n³/ε cells whatever the values are.
NP-complete problems are all equally hard to solve exactly, in the sense that each reduces to every other. Those reductions do not preserve how good an approximate answer is, and the optimisation versions fall into very different classes. Some have an approximation scheme: for every ε > 0 a polynomial-time algorithm within a factor 1 + ε. Knapsack has a fully polynomial one, with time polynomial in 1/ε as well (Oscar Ibarra and Chul Kim, 1975); points in the plane have a scheme for the travelling salesman (Sanjeev Arora, 1996, and independently Joseph Mitchell). Some problems have a constant factor and provably nothing better than some other constant. Set cover has a logarithmic factor and no constant. Clique has essentially nothing.
A hardness threshold is a theorem of the form “achieving ratio r in polynomial time would imply P = NP”. The oldest is the one run in the demo: Sartaj Sahni and Teofilo Gonzalez (1976) observed that for the travelling salesman with arbitrary distances any constant ratio at all would decide Hamiltonian cycle. Thresholds for problems such as MAX-3SAT, vertex cover and clique were out of reach until the PCP theorem of the next demo. With it, Johan Håstad proved in 2001 that beating 7/8 for MAX-3SAT by any constant is NP-hard, so the coin-flipping algorithm is the best possible unless P = NP.
Several bars still have a gap. The Unique Games Conjecture, proposed by Subhash Khot in 2002, asserts that a particular constraint-satisfaction problem is NP-hard to approximate. If it is true, many gaps close exactly: factor 2 is optimal for vertex cover (Khot and Oded Regev, 2008), and the Goemans–Williamson constant 0.878… is optimal for Max Cut (Khot, Guy Kindler, Elchanan Mossel and Ryan O’Donnell). The conjecture is open, and researchers are divided about it. Every statement that depends on it is conditional, and the demo marks those separately from the theorems.
The grid is a proof, and the verifier reads only three of its cells: flip some cells, run the test, and watch the chance of being caught track how wrong the table is. Then slide an approximation ratio into the gap below.
Tap any cell to flip it. Lime rings: the two cells chosen by coin flips. Teal ring: the third cell, x ⊕ y, which the first two determine. Rose dots: cells where the table differs from the nearest linear function, found by comparing with all 64 of them. On the chart, lime dots are random corruptions of random linear functions, the indigo ring is your table, and the short lime bar is your measured rejection rate. This is the linearity test only, on a 64-cell table. It is not a PCP: a real one encodes a whole NP witness in such tables (exponentially long ones, in the simplest textbook construction) and adds further tests to check that the encoded witness is valid.
A proof checked by a few random queries is a formula with a gap: either every local check can pass, or a constant fraction must fail. Slide the approximation ratio into the gap.
This panel is a diagram of the argument, not a computation: the rose shape only marks where false statements can land: at most 7/8 + ε (Håstad, 2001; drawn with ε = 0.01). Emerald: formulas from true statements. Sky: the algorithm’s guarantee. Hatched: the gap. Producing a gap at all is the content of the PCP theorem; without it a false statement could map to a formula with all clauses but one satisfiable, and no approximation algorithm would notice.
The PCP theorem says that every proof of an NP statement can be rewritten in a form that a randomised verifier checks by reading only a constant number of its bits: a correct proof is always accepted, and for a false statement every purported proof is rejected with constant probability. In symbols, NP = PCP(log n, O(1)): logarithmically many random bits, constantly many queries. It was proved in 1992 by Sanjeev Arora and Shmuel Safra and by Arora, Carsten Lund, Rajeev Motwani, Madhu Sudan and Mario Szegedy, building on the theory of interactive proofs. Irit Dinur gave a combinatorial proof by gap amplification in 2006. See also: Proofs as Conversations.
The demo runs one ingredient only, and is not a PCP. The linearity test of Manuel Blum, Michael Luby and Ronitt Rubinfeld (1990) reads f(x), f(y) and f(x ⊕ y) for random x and y. If f is at distance δ from the nearest linear function, the test rejects with probability at least δ. Writing f̂(S) for the correlation of f with the linear function of the subset S, the rejection probability is exactly ½ − ½ Σ f̂(S)3, and the bound follows because the squares of the f̂(S) add up to 1. In the algebraic proof of the theorem the prover writes the witness in an error-correcting code built from linear functions, so that any lie is smeared across many positions, and tests like this one are how the verifier confirms that the table it is reading is a codeword at all.
The link to approximation was found by Uriel Feige, Shafi Goldwasser, László Lovász, Shmuel Safra and Mario Szegedy in 1991, for Clique. In the form used here: the verifier’s possible checks, one for each outcome of its coins, are constraints on the bits of the proof. For a true statement some proof satisfies all of them; for a false one every proof violates a constant fraction. So the PCP theorem is equivalent to a statement about approximation: there is a constant ρ < 1 such that telling satisfiable 3-CNF formulas from those in which at most a ρ fraction of the clauses can be satisfied is NP-hard. An approximation algorithm with ratio better than ρ would tell them apart.
All of these hardness results are conditional on P ≠ NP, which is unproved. What is proved is the implication: an algorithm beating the threshold would give P = NP.
Spot a mistake or have an idea?