P, NP, and verification
◈ 5 cardsDefine P (poly-time decidable) and NP (poly-time verifiable via a polynomial-length certificate), see why P ⊆ NP, and meet the open P-vs-NP question through HAM-CYCLE and 3-CNF-SAT certificates.
Two kinds of "easy"
Every algorithm so far in this course ran in polynomial time — for some constant . We call such problems tractable, and the class of all of them is P. Formally, a decision problem (one with a yes/no answer) is a language — the set of input encodings whose answer is "yes". Then
NP captures a weaker notion of easy: not "can you solve it fast?" but "can you check a proposed answer fast?" The proposed answer is called a certificate . A problem is in NP if there is a polynomial-time verification algorithm such that
Read it carefully: is a yes-instance iff some polynomial-length certificate makes the verifier accept. The certificate must be short (polynomial in ) — an exponential-length "proof" would not help, because you could not even read it in polynomial time. NP stands for nondeterministic polynomial: a hypothetical machine that could "guess" the right and then verify it would run in polynomial time.
Why P ⊆ NP
Every problem you can solve fast you can also verify fast: ignore the certificate entirely and just re-solve from scratch. So a poly-time decider for is already a poly-time verifier (with an empty or ignored certificate), giving . The trillion-dollar open question is whether the containment is strict:
Most computer scientists believe — for thousands of NP problems we can verify a solution in a heartbeat but finding one seems to require exhausting exponentially many candidates. It has been open since Cook's 1971 paper and carries a \$1{,}000{,}000 Clay Millennium Prize. Nobody has proved it either way.
Worked example — two certificates
HAM-CYCLE asks: does graph have a Hamiltonian cycle (a simple cycle visiting every vertex exactly once)? Finding one seems to need trying up to orderings. But checking is trivial:
- Certificate : a sequence of the vertices, claimed to be the cycle.
- Verifier : confirm lists every vertex exactly once, and that each consecutive pair (and the wrap-around) is an edge of . That is — clearly polynomial.
So HAM-CYCLE NP even though no polynomial solver is known.
3-CNF-SAT asks: is a boolean formula in 3-conjunctive-normal-form (an AND of clauses, each an OR of exactly 3 literals) satisfiable? For variables there are assignments to search.
- Certificate : a truth assignment to all variables, e.g.
- Verifier: plug into the formula and evaluate. Linear in the formula length.
Again, easy to check, seemingly hard to find — the signature of an NP problem.
Optimization vs. decision
NP-completeness theory is stated for decision problems, but real problems are usually optimization problems (find the shortest path, the largest clique). The trick: an optimization problem is no easier than its decision version. SHORTEST-PATH (find the shortest path) has a decision cousin PATH (is there a path of edges?). If you could solve the optimization version fast, you could answer the decision version fast (just compare the optimum to ). So proving the decision problem hard proves the optimization problem at least as hard — which is exactly the direction we want.