core34 min studyLesson 239 in Mathematics

Reductions and NP-completeness

Translate decision instances with a polynomial-time equivalence, prove certificate membership, and preserve the direction of hardness.

On this page

What you’ll understand

  • Define P, NP, NP-hardness, and NP-completeness for encoded decision problems.
  • Prove both directions and polynomial construction cost of a reduction.
  • Distinguish an unresolved complexity separation from a theorem about a particular instance.

An algorithmic problem can look unrelated to another until one instance is encoded inside the other. A reduction formalizes that translation and transfers an algorithm for the target back to the source. Hardness proofs run this implication in a deliberate direction: if a known difficult source could be translated to your problem, then a fast solver for your problem would also solve the source. The translation must preserve every yes and no answer and fit within polynomial resources.

Verification and discovery are different tasks

Use finite binary encodings and deterministic polynomial time as the baseline model. P contains decision problems with polynomial-time algorithms. NP contains decision problems whose yes instances have certificates of polynomial length that a deterministic verifier checks in polynomial time; for a no instance, no certificate is accepted. Guessing a certificate and checking it motivates the letter N through nondeterminism, not through the phrase nonpolynomial. Every problem in P is in NP by ignoring the certificate.

For vertex cover, the decision instance is a finite simple graph and an integer budget k. A certificate lists at most k vertices, and a verifier checks that every edge touches the list. With a suitable membership representation, checking takes polynomial time in the explicit graph encoding. This proves membership in NP, not hardness. An optimization problem asking for the smallest cover is related but has a different output specification; NP-complete is formally a classification of decision problems here.

A≤pB⟺(∃ polynomial-time f)(∀x) [x∈A  ⟺  f(x)∈B]A\le_p B\quad\Longleftrightarrow\quad (\exists\text{ polynomial-time }f)(\forall x)\ [x\in A\iff f(x)\in B]
This is a polynomial-time many-one reduction. One target decision answer solves the corresponding source instance, after a polynomial-time construction.↔ Scroll wide equations horizontally.

Transfer hardness in the correct direction

If A reduces to B and B has a polynomial-time decision algorithm, composing the construction with that solver gives one for A. Thus to prove B hard, start from a known hard A and build B instances. Reducing B to an easy or hard problem in the other direction gives an upper-bound relation instead and does not establish the intended hardness. Composition also requires polynomial output length; a construction that prints an exponentially large graph is not polynomial simply because each printed edge is easy to describe.

A problem is NP-hard if every NP decision problem reduces to it under the chosen reduction. It is NP-complete if it is additionally in NP. Starting from the Cook–Levin theorem that satisfiability is NP-complete, chains of proved reductions establish many others. In this lesson, use the established NP-completeness of Independent Set as the source and prove its simple translation to Vertex Cover. Proving a new link does not require reproving the entire foundational theorem each time, but the starting theorem must be stated rather than assumed invisible.

S⊆V independent  ⟺  V∖S is a vertex cover,∣V∖S∣=∣V∣−∣S∣S\subseteq V\text{ independent}\iff V\setminus S\text{ is a vertex cover},\qquad |V\setminus S|=|V|-|S|
An edge has both endpoints outside the complement exactly when it has both endpoints in S. This complement identity gives the decision reduction with a transformed threshold.↔ Scroll wide equations horizontally.

What hardness does and does not say

Given an Independent Set instance (G,k) with n vertices and a valid threshold from zero through n, output the Vertex Cover instance (G,n−k). The complement identity proves yes if and only if yes. The graph is unchanged and the threshold subtraction is polynomial in its encoded length. A cover verifier establishes target membership, so the known source hardness makes Vertex Cover NP-complete. Out-of-range thresholds can be resolved directly or mapped to fixed yes/no instances without affecting the result.

It remains unproved whether P equals NP. Therefore NP-completeness does not constitute an unconditional theorem that no polynomial-time algorithm exists. Under P ≠ NP, no deterministic polynomial-time exact decision algorithm solves all instances of an NP-complete problem. Some restricted graph families, parameter ranges, and individual instances can still be easy. Promise problems restrict allowed inputs explicitly; a reduction to such a problem must satisfy its promise on every produced instance. Ignoring that obligation can invalidate an otherwise plausible hardness argument.

Translate an independent-set threshold

Let G be the five-vertex path 1−2−3−4−5. Translate the question of an independent set of size at least three into a Vertex Cover question, and provide certificates for both yes answers.

  1. There are five vertices, so the new cover threshold is 5−3 = 2. The reduction retains exactly the same four edges and changes only the requested budget.

  2. The set {1,3,5} has size three and no edge with both endpoints inside it. Its complement {2,4} touches all four path edges and has size two.

  3. Conversely, any cover with at most two vertices has an independent complement with at least three vertices. The same complement argument works for every explicit finite simple graph, so the example illustrates a universal equivalence rather than proving it by enumeration.

The result

The translated instance asks for a cover of size at most two and is a yes instance. Both witnesses can be checked directly against the four-edge input.

Explore the model

Interactive lab

Interactive lab · modular

Encode a small cycle, then translate a certificate

Pause and reset, then set both controls to modulus 6 and additive step 1. Step through residues and regard consecutive residues, including 5 back to 0, as edges of an undirected six-cycle. On paper predict that {0,2,4} is independent and its complement covers every edge. For a fresh comparison, pause and reset, then set modulus 5 and step 1; test the complement of {0,2}. The instrument draws an additive orbit, not an NP solver or a hardness proof; you check the graph certificates separately.

Encode a small cycle, then translate a certificateAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA reduction translates a specification and its certificates; inspecting a few easy instances does not establish or refute NP-hardness.

Check your understanding

To prove a problem B is NP-hard using a known NP-hard decision problem A, which reduction direction is needed?

Try it yourself

A graph G has eight vertices. Translate an Independent Set threshold of five into a Vertex Cover threshold. Then explain what can be concluded if someone supplies a deterministic polynomial-time algorithm for Vertex Cover on every finite simple graph.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use the complement size and then compose the solver with the reduction. Keep the status of P versus NP explicit.

Compare with the solution

The cover threshold is eight minus five, or three. An independent set of at least five has a cover complement of at most three, and conversely. A polynomial-time algorithm for every Vertex Cover instance would solve Independent Set through this reduction and, because Vertex Cover is NP-complete, would imply P = NP. This is a conditional implication, not a proof that such an algorithm is impossible. A solver restricted to paths would not trigger the conclusion because the reduction produces general graphs, not only paths.

Take it with you

  • NP means polynomially verifiable yes certificates under an encoded decision model.
  • A hardness reduction goes from a known hard source to the proposed hard target.
  • NP-completeness is a proved classification; P ≠ NP remains an unresolved separation.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.