← All posts

Algorithms Archive

NP-Completeness: Formal Definition, Proof Sketches, and Reductions

There is a moment in algorithm design where the problem stops feeling like an implementation challenge and starts looking like a warning sign. You try dynamic programming. You try graph modeling. You try a greedy invariant. Every route seems to move the difficulty somewhere else instead of removing it.

NP-completeness is the language for that moment. It does not prove that your problem is impossible to solve quickly. It does something more precise and more useful: it says that a polynomial-time algorithm for this problem would also give polynomial-time algorithms for every problem whose solutions can be checked efficiently.

In this post

  • We will define P, NP, NP-hard, and NP-complete in the decision-problem model.
  • We will separate verification from search, because that is the whole tension behind P vs NP.
  • We will use reductions as the proof mechanism.
  • We will sketch why Cook's SAT result and Karp's reductions changed algorithm design.
  • We will connect the idea back to the Algorithms pillar and practical design choices.

The question

Suppose a problem gives you a proposed solution and asks: "Can you check this quickly?"

For many problems, the answer is yes. If someone hands you a Hamiltonian cycle, a satisfying assignment, a clique, or a traveling-salesperson tour under a stated budget, checking the certificate is straightforward. The harder question is whether you can find the certificate quickly from scratch.

The Clay Mathematics Institute frames P vs NP around exactly this gap: if a solution is easy to check, must it also be easy to find? That is not just a philosophical question. It decides whether a huge class of search, scheduling, routing, allocation, and verification problems have efficient exact algorithms.

Intuition

Think of NP as a class of problems with short receipts.

For a yes-instance, there is some certificate that convinces a verifier in polynomial time. The verifier does not need to know how the certificate was found. It only needs to check it.

NP-completeness says that some problems are universal bottlenecks for this entire class. If you can solve one NP-complete problem in polynomial time, you can solve every problem in NP in polynomial time by translating instances into that problem and translating the answer back.

That translation is the reduction.

Formal statement

Work with decision problems, so each input has answer yes or no.

  • P is the class of decision problems solvable in polynomial time by a deterministic algorithm.
  • NP is the class of decision problems where yes-instances have polynomial-size certificates verifiable in polynomial time.
  • A problem A is NP-hard if every problem B in NP can be reduced to A in polynomial time.
  • A problem A is NP-complete if A is in NP and A is NP-hard.

The most common reduction shape here is a polynomial-time many-one reduction. For languages B and A, we write B <=p A when there is a polynomial-time computable function f such that:

\[ x \in B \iff f(x) \in A \]

So if A has a polynomial-time solver and B <=p A, then B has a polynomial-time solver: compute f(x), solve A, and return the same yes/no answer.

Model and assumptions

This post uses the standard asymptotic model from complexity theory:

  • Inputs are finite strings or clean encodings of combinatorial objects.
  • "Efficient" means polynomial time in the input length.
  • Reductions must be computable in polynomial time.
  • We focus on decision versions of problems, because NP-completeness is defined for languages.
  • Optimization problems can often be connected to decision versions by asking whether there is a solution with value at most or at least a threshold.

These assumptions matter. If the reduction is too expensive, it does not transfer efficient solvability. If the problem is not in NP, it may be NP-hard without being NP-complete. If we silently switch from optimization to decision, we must state the threshold version clearly.

Proof sketch

To prove that a new problem A is NP-complete, the proof has two jobs.

First, show A is in NP. That means describing the certificate and the polynomial-time verifier.

Second, show A is NP-hard. Pick a known NP-complete problem B and give a polynomial-time reduction B <=p A. The reduction must preserve yes/no answers:

\[ B\text{ is yes} \iff A\text{ instance produced by the reduction is yes} \]

The proof usually has three parts:

  1. Construction: define how an instance x of B becomes an instance f(x) of A.
  2. Runtime: argue that f is computable in polynomial time.
  3. Correctness: prove both directions of the iff statement.

This is why reductions are easy to misuse. A reduction is not just a clever analogy between two problems. It is a transformation with a runtime bound and a bidirectional correctness argument.

Worked example shape

Imagine you want to prove that a scheduling problem is hard.

You might start from a known NP-complete problem such as SAT or 3-SAT. Variables and clauses become scheduling gadgets. A truth assignment becomes a choice of schedule components. Clause satisfaction becomes a feasibility constraint.

The reduction is successful only if:

  • every satisfying assignment creates a feasible schedule, and
  • every feasible schedule can be decoded into a satisfying assignment.

The second direction is often where weak proofs fail. It is not enough to show that your construction can represent solutions. You must show that any solution to the constructed instance corresponds to a valid solution of the original instance.

Why Cook and Karp mattered

Stephen Cook's 1971 theorem gave the first central NP-completeness result by showing that satisfiability sits at the core of efficient verification. Richard Karp's 1972 paper then showed that many natural combinatorial problems are tied together by polynomial reductions.

Karp's result made NP-completeness feel less like an artifact of logic and more like a map of real algorithmic terrain. Covering, matching, packing, routing, assignment, sequencing, and graph problems could now be studied through a shared hardness language.

That is why NP-completeness changed the daily practice of algorithm design. It gave engineers and researchers a disciplined way to stop searching for the wrong kind of exact polynomial-time algorithm and start asking better questions.

Why this matters

NP-completeness is not a reason to give up. It is a reason to change the target.

Once you have credible hardness evidence, you can ask:

  • Are real inputs small enough for exponential search with pruning?
  • Is there a special case with extra structure?
  • Is approximation good enough?
  • Is randomization useful?
  • Can parameterized complexity isolate the true source of difficulty?
  • Should the product surface uncertainty instead of pretending the exact optimum is cheap?

This is the practical value of theory. A hardness proof does not ship a feature, but it can prevent months of chasing a fantasy algorithm.

Internal trail

Further reading

Reusable artifact

Questions readers usually ask

Does NP-complete mean impossible to solve quickly?

No. NP-complete means that a polynomial-time exact algorithm for this problem would imply polynomial-time algorithms for every problem in NP. It is strong evidence to change the design target, not a proof that every useful instance is hopeless.

Why do NP-completeness proofs use decision problems?

The definitions of P, NP, and NP-completeness are stated for languages with yes/no answers. Optimization problems usually enter the framework through threshold versions, such as asking whether there is a tour with cost at most K.

What is the most common weak point in a reduction proof?

The reverse direction. It is not enough to show that a satisfying source solution creates a target solution. You also need to show that every target solution decodes into a valid source solution.

Next questions

  • What does a reduction proof look like when every gadget has to be drawn explicitly?
  • When does an approximation algorithm give a useful guarantee for an NP-hard optimization problem?
  • Which special cases of a hard problem explain why production inputs are still tractable?

Corrections and clarifications

If a technical claim in this essay needs correction, it will be logged on the public Errata page with the affected claim, correction, and date.

/ Continue

Follow the technical trail.

Use the dense notes as the source material, then move through the guided route, writing, or project proof when you want a cleaner entry point.

Corrections and clarifications for this post are tracked through the errata page.