NP is about verification, not non-determinism
A problem is in NP when a claimed solution can be checked quickly. The name comes from an older definition and misleads.
P is what can be solved in polynomial time; NP is what can be verified in polynomial time. Whether they are equal is the central open question, and the NP-complete problems are the ones on which it turns.
Core ideas
The classification is about the problem, not about any particular algorithm, and knowing it changes what you should attempt.
A problem is in NP when a claimed solution can be checked quickly. The name comes from an older definition and misleads.
Everything in NP reduces to them, so a polynomial algorithm for one gives one for all.
"NP-complete" means stop looking for an exact efficient algorithm and consider approximation, heuristics or special cases.
The material
Definitions, examples, reductions, and what the classification means in practice.
The class of decision problems solvable by an algorithm running in time O(nᵏ) for some constant k, where n is the input size. Informally: efficiently solvable.
The class of decision problems for which a proposed solution can be verified in polynomial time. Informally: if someone hands you an answer, you can check it quickly.
The name stands for nondeterministic polynomial, from an older definition using a machine that guesses. The verification definition is equivalent and far more intuitive: NP is not "not polynomial", and P is a subset of NP.
Every problem in P is in NP: if you can solve it quickly you can verify a claimed answer quickly by solving it and comparing. The reverse inclusion is the open question.
Problem A reduces to B if any instance of A can be transformed in polynomial time into an instance of B with the same answer. Then an efficient algorithm for B gives one for A, so B is at least as hard as A.
A problem is NP-complete if it is in NP and every problem in NP reduces to it. It is NP-hard if the second condition holds whether or not it is in NP.
SAT — deciding whether a propositional formula is satisfiable — is NP-complete. It was the first problem shown to be so, and every subsequent NP-completeness proof reduces from a problem already known to be complete.
“Tautology, Contradiction, Satisfiability” in Logic and Proof raised the question and named the result; here is what it means. Thousands of problems are now known to be NP-complete: Hamilton circuit, 3-colouring, subset sum, the travelling salesman decision problem, 0/1 knapsack, and clique among them.
They are all equivalent in the sense that matters: a polynomial-time algorithm for any one would give one for all of them, and hence P = NP. Fifty years of effort has produced neither such an algorithm nor a proof that none exists.
Being NP-complete is a worst-case statement and does not mean instances are hard in practice. Industrial SAT solvers routinely handle formulas with millions of variables, because real instances have structure. The classification tells you what to expect in general and not what will happen on your data.
If P = NP were proved constructively, essentially every optimisation problem would become tractable and public-key cryptography would collapse. Most researchers expect P ≠ NP; nobody has proved it, and it is one of the Clay Millennium Problems.
Interactive
Counts from running, not from quoting
Method
Verification first; it is the cheapest test.
If yes, the problem is in NP. This is usually obvious and is the first step.
Then it is in P. Shortest path, sorting, primality, matching, minimum spanning tree.
Hamilton circuit, SAT, 3-colouring, subset sum, clique. A reduction from one of these proves NP-hardness.
In P: find the algorithm. NP-complete: approximate, restrict or use a solver. Undecidable: change the question.
The clearest pair on this path.
“Euler and Hamilton Paths” in Graphs and Trees presented both and noted the contrast; this is what the contrast means. Verifying a Hamilton circuit is easy, which puts it in NP; finding one is believed hard, which is the P versus NP question in miniature.
For a problem you are handed, decide whether a solution is quickly verifiable, whether it resembles a known complete problem, and what you would attempt in each case. The last part is the point.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.