Suppose you must find a route that visits every city and costs at most 100. Finding such a route may be difficult. If someone hands you one, checking it is much easier: confirm that it visits every city once, add the costs, and compare with 100. This difference between finding and checking leads to one of the central questions in theoretical computer science.
Background for this page. A decision problem asks for a yes-or-no answer. A certificate is evidence for a yes answer. Polynomial time is measured against the encoded input length, including the bits needed to represent numbers. Related explanations: Big O, Big Omega, and Big Theta · Approximation algorithms: guarantees and lower bounds.
For decision problems—questions with a yes-or-no answer—P is the class solvable in polynomial time by a deterministic algorithm. NP is the class whose yes answers have certificates that can be checked in polynomial time. Every problem in P is also in NP, because we can solve it and then report the answer. Whether P = NP is still open. We do not know whether every problem with quickly checkable yes certificates can also be solved quickly.
An NP-hard problem is at least as hard as every problem in NP under the relevant polynomial-time reductions. An NP-complete problem is both NP-hard and in NP. A reduction transforms instances of one problem into instances of another in polynomial time while preserving yes and no answers. If we could solve one NP-complete problem in polynomial time, reductions would give polynomial-time algorithms for every problem in NP.
The direction of a reduction matters. To show a new problem is NP-hard, take a problem already known to be NP-hard and transform its instances into instances of the new problem. Showing only that the new problem can be converted into an old hard problem does not establish the claim.
The Boolean satisfiability problem, SAT, asks whether some assignment of true and false values makes a formula true. It is a standard starting point for NP-completeness proofs. The route question above is a decision version of traveling-salesperson: “Is there a tour of cost at most B?” Its optimization version asks for the least-cost tour. We must distinguish those versions when talking about NP, certificates, or approximation.
NP-complete does not mean someone has proved that the problem requires exponential time. No polynomial-time algorithm is known for an NP-complete problem, and no proof rules one out. For an actual task, small inputs, special structure, exact exponential methods, and approximation may all be useful. A complexity classification guides the search for a method; it does not solve the practical problem by itself.
Read the reduction as an algorithm
To prove a new decision problem Q NP-hard, start with a known NP-hard problem such as SAT. Construct a polynomial-time transformation f so a SAT instance x is satisfiable exactly when f(x) is a yes instance of Q. If Q had a polynomial-time solver, transform x and call that solver. The combined procedure would solve SAT in polynomial time.
Both directions of the equivalence matter. Mapping every satisfiable formula to a yes instance is insufficient if an unsatisfiable formula might also become yes. The transformation must not smuggle in solving SAT as a supposedly cheap step.
To establish NP-completeness, additionally show Q belongs to NP by describing a polynomial-size certificate and a polynomial-time verifier. Hardness alone does not provide membership.
Practice. Someone gives you a proposed tour of ten cities with a claimed cost of 80. What must you check? If a new problem reduces to SAT, have you proved the new problem NP-hard?
Answer. Check that the route visits every required city exactly once, returns as required, and that its edge costs sum to 80. No. Reducing the new problem to SAT shows how SAT could help solve it; NP-hardness needs a reduction from a known hard problem to the new one.
Try another case. If checking a certificate takes time polynomial in a numerical value written in binary, is that automatically polynomial in input length?
Reasoning. No. A value can be exponential in its bit length. Algorithms must measure work against the encoding size when claiming polynomial time.