Problems with Checkable Answers

NP is the class of puzzles whose solutions are easy to check. Hand a verifier a certificate, watch a machine guess, and notice how much harder it is to certify that no solution exists

Problems with Checkable Answers

NP is the class of problems where, if the answer is yes, there is a short piece of evidence that makes it easy to be sure: a route, a colouring, a factor. It says nothing about how to find that evidence. And it says nothing at all about how to be sure when the answer is no.

The Verifier’s Bench

You are the prover: press Clear, tap vertices to build a tour of your own, and press Check to watch the verifier test it. Then try a new instance or another problem, and compare the sky bar (its checks) with the rose bar (the candidates you were choosing from).

A graph with a tour hidden in it · 10 vertices, 13 edgesIs there a round trip along the edges that visits every vertex exactly once?
A1B2C9D4E8F5G3H10I7J6
Verifier: checks made21
Search space: candidates181,440

check 21: H–A is an edge, closing the tour ✓Verifier: ACCEPT

10 of 10
vertices on your tour (the certificate)
21
checks the verifier has made
181,440
candidates in the search space
—
partial tours examined by Search for me
Accepted after 21 checks. The verifier did no searching: it only followed the certificate it was handed, however that certificate was found among the 181,440 candidates. Press Clear and try to find a certificate yourself, or ask for a new instance.

Amber is your certificate, sky is the verifier’s work, rose is search. The bars are on a logarithmic scale: each tick is ten times the one before. The search space counts every candidate a prover could hand over: (n − 1)!/2 orderings of n vertices, 3n colourings, C(n, k) subsets of size k, or the divisors up to √N. Search for me uses backtracking, which drops a partial candidate as soon as it breaks a rule, so on graphs this small it examines far fewer; that says nothing about how the work grows on large graphs. Trial division gives up after 60,000,000 divisors. For numbers, one check is a whole long division, which costs roughly the square of the number of digits in single-digit steps.

Go deeper:What NP Means

A decision problem is in NP if there is a verifier V, a deterministic algorithm running in polynomial time, with this property: the answer for an input x is yes exactly when some certificate c, of length polynomial in the length of x, makes V(x, c) accept. The bench runs four such verifiers. A tour through n vertices is checked in at most 2n + 1 look-ups, a colouring in one look-up per vertex and per edge, a clique of size k in one per pair, and a factor in a single division. A wrong certificate is always rejected, and when the answer is no, every certificate is wrong.

P is the class of problems that can be solved in polynomial time, with no certificate at all. P is contained in NP, since a verifier is free to ignore what it is handed and work the answer out. The question P = NP? asks whether the reverse holds: whenever a solution can be checked quickly, can one also be found quickly? Most researchers believe not, but nobody has proved it. The bars on the bench show how much room there is between the two (a few dozen checks against millions of candidates), but a count of candidates is not a lower bound: the bench’s own search already skips most of them, and a proof that P ≠ NP would have to rule out every cleverer method as well.

Stephen Cook framed the question in 1971, and Leonid Levin did so independently in the Soviet Union at about the same time. Richard Karp’s 1972 paper, which showed that a long list of familiar problems are all equally hard, gave the class its name. Kurt Gödel had asked essentially the same thing in a 1956 letter to John von Neumann: how many steps does a machine need to find a proof of a given length, if one exists?

NP stands for nondeterministic polynomial time, a name explained by the next demo. It does not stand for “non-polynomial”, and problems in NP are not unsolvable: each of the four here is solved outright by trying every certificate, which takes exponential time but always finishes. See also: P versus NP in the Computational Complexity module, which compares finding with checking on Subset Sum.

The Guessing Machine

This is the computation tree of a machine that is allowed to guess. Walk it three ways (Lucky guesser, All at once, Deterministic simulation), then switch to the exact-cover machine and add pieces to watch the number of branches double.

8
steps on the longest branch
8
branches (leaves of the tree)
1
branches that accept
22 of 34
configurations a branch-by-branch search visits before it can answer
0001
the lucky guesses: a certificate
After 8 steps there are 4 configurations side by side. The machine accepts if any branch ends in accept (emerald), and here one does. This machine makes one real guess, where the pair starts, so an input of 7 symbols has only 8 branches. Switch to the exact-cover machine to see a tree that doubles.

Each dot is a configuration: a state, a tape and a head position. Time runs downwards; the path forks where the rule table offers two options. Amber is the certificate (the list of guesses, 0 for the first option and 1 for the second), rose is deterministic search, emerald leaves accept. The pair machine accepts when some symbol equals the one three cells to its right; the exact-cover machine guesses skip (0) or take (1) at each piece and accepts when the pieces it took cover all four cells exactly once. Both are toys: each of these two languages can also be decided quickly without guessing, the second because there are only four cells to keep track of. With an unlimited number of cells, exact cover is NP-complete (it is on Karp’s 1972 list), and no fast deterministic method is known. Inputs are capped at 10 symbols and 8 pieces (a tree of 767 configurations).

Go deeper:Nondeterminism Is a Definition, Not a Device

A nondeterministic Turing machine is an ordinary one whose rule table may list more than one option for the same state and symbol. Its possible runs on an input form a tree, and the machine is said to accept if at least one branch ends in the accept state. NP was first defined as the class of problems decided by such a machine with every branch at most polynomially long. No physical device works this way. Nondeterminism is a way of describing a class of problems, not a proposal for a computer.

The two definitions of NP agree, and the tree shows why. If some branch accepts, the list of choices made along it is a certificate: it is no longer than the branch, and a deterministic machine can check it by following the listed choices one at a time, which is what the lucky-guesser view does. In the other direction, a nondeterministic machine can guess a certificate symbol by symbol and then run the verifier on it. So “some branch accepts within polynomial time” and “some polynomial-length certificate passes a polynomial-time check” describe the same problems.

A deterministic machine can always simulate a nondeterministic one by exploring the tree branch after branch. A tree of depth t in which each step offers two options can have 2t leaves, so in general the simulation takes exponential time. Whether that cost can always be avoided, by some method other than walking the tree, is exactly the P versus NP question. The two machines here are toys with trees of at most a few hundred configurations, and both of their languages happen to be easy; the doubling you see is a property of the tree, not a proof that anything is hard.

Proving No

Three cases of a “no” answer. Delete a vertex of the Petersen graph and compare the evidence for yes with the evidence for no; seat the pigeons by hand while a solver’s proof that it cannot be done explodes; then enter a prime and watch a short certificate of primality being verified.

ABCDEFGHIJ
Evidence for yes: a tour (the certificate)
searching…
The search so far: partial tours tried, by length
2345678910
Tap any vertex to delete it; tap it again to put it back.
10, 15
vertices and edges
181,440
orderings a tour could follow
0
partial tours the search tried
—
look-ups to check a tour: there is none to check
Searching for a tour: 0 partial tours tried so far.

The search starts at A, extends the tour one edge at a time and backs up at a dead end. Each rose bar counts the partial tours of one length that it tried; an amber cycle is a tour it found. Ten vertices are few enough that the failed search is short. The point is the difference in kind: a yes comes with something to check, a no comes with nothing but the search.

Go deeper:co-NP, Proof Systems and Certificates of Primality

The problems whose no answers have short, quickly checkable certificates form the class co-NP. “This graph has no Hamiltonian cycle” and “this formula has no satisfying assignment” are in co-NP, and nobody knows how to give short certificates for them in general. Whether NP = co-NP is open. If P = NP then the two are equal, since a fast solver settles both answers, so proving NP ≠ co-NP would also prove P ≠ NP; most researchers believe both inequalities, and neither is proved.

A problem in both NP and co-NP has short evidence either way. Jack Edmonds drew attention to such problems in 1965, calling this a good characterisation. Primality is the classic example. A factor certifies that a number is composite, and in 1975 Vaughan Pratt showed that primes have short certificates too: a number g whose powers take N − 1 different values modulo N, which is possible only when N is prime, together with the prime factorisation of N − 1 and, recursively, certificates for the primes in it. The tree has fewer nodes than N has binary digits. That placed primality in NP ∩ co-NP long before Manindra Agrawal, Neeraj Kayal and Nitin Saxena proved in 2002 that it is in P. Factoring, phrased as a yes-or-no question (does N have a factor below k?), is also in NP ∩ co-NP, which is one reason it is not expected to be NP-complete: if it were, NP would equal co-NP.

The pigeonhole panel is about a specific proof system. The failed search tree of a DPLL solver is a proof in a system called resolution, and Armin Haken proved in 1985 that every resolution proof of the pigeonhole formulas has exponential size. That is a theorem about one way of writing proofs. Stronger proof systems have short proofs of the pigeonhole principle, which is, after all, obvious. The curve in the demo is this module’s DPLL solver on a handful of small cases: it is consistent with Haken’s theorem and is not a proof of it.

Stephen Cook and Robert Reckhow showed in 1979 how the two ideas meet: NP = co-NP exactly when there is a proof system in which every unsatisfiable formula has a short refutation. So proving NP ≠ co-NP means showing that every proof system, however ingenious, has some family of statements it cannot prove briefly. Haken’s theorem does that for resolution. For the strongest systems in common use, no such family is known.

Key Takeaways

  • A problem is in NP when every yes answer has a short certificate that a fast verifier accepts.
  • A machine that guesses and a verifier that checks define the same class: the guesses are the certificate.
  • NP promises nothing about no answers; whether they too always have short certificates (NP = co-NP) is open.
  • Checking can be vastly cheaper than any search we know, but nobody has proved that searching is necessary.

Spot a mistake or have an idea?

Search