47.02.03 · theoretical-cs / complexity-fundamentals

Classic NP-Complete Problems: SAT, 3SAT, Clique, Vertex Cover, and Hamiltonian Cycle

shipped3 tiersLean: nonepending prereqs

Anchor (Master): Sipser 2013 Introduction to the Theory of Computation 3e (Cengage) §7.4-7.5; Cormen, Leiserson, Rivest & Stein 2022 Introduction to Algorithms 4e (MIT Press) §34.3-34.5; Garey & Johnson 1979 Computers and Intractability (Freeman) §2-3 (catalogue of NP-complete problems, reduction strategies, strong NP-completeness)

Intuition Beginner

Some problems have a convenient property: once you find a solution, checking it is easy. A jigsaw puzzle is hard to solve, but verifying that a completed puzzle is correct takes a glance. A Sudoku is hard to fill in, but checking a filled grid is quick.

NP-complete problems are the hardest problems in NP — the hardest problems where solutions can be checked quickly. If you could solve any one of them quickly, you could solve all of them quickly, because they are all secretly the same problem in disguise.

The disguises are called reductions. A reduction from problem A to problem B is a fast translation: it converts any instance of A into an instance of B such that the answer is preserved. If you can solve B, the reduction lets you solve A by translation. When A reduces to B and B is in NP, then B is at least as hard as A.

SAT asks: given a Boolean formula, is there a way to set its variables to true and false that makes the whole formula true? Cook and Levin proved that SAT is NP-complete: every problem in NP reduces to SAT. This was the first known NP-complete problem.

From SAT, a chain of reductions connects dozens of seemingly unrelated problems. 3SAT (a restricted form of SAT) reduces to CLIQUE (does a graph have a group of mutually connected vertices of a given size?), which reduces to VERTEX-COVER (can you delete a small set of vertices to eliminate all edges?), and so on. Each reduction opens a new window into the same underlying hardness.

Visual Beginner

The reduction chain connecting NP-complete problems:

Any NP problem
       |
       ↓  (Cook-Levin)
      SAT
       |
       ↓  (clause splitting)
     3SAT
      / \
     ↓   ↓
  CLIQUE  HAM-CYCLE
     |
     ↓  (complement graph)
  VERTEX-COVER
     |

  SUBSET-SUM
Problem Input Question
SAT Boolean formula Is it satisfiable?
3SAT Formula with 3-literal clauses Is it satisfiable?
CLIQUE Graph , integer Does have a -clique?
VERTEX-COVER Graph , integer Does have a -vertex cover?
HAM-CYCLE Graph Does have a Hamiltonian cycle?

Worked example Beginner

We reduce 3SAT to CLIQUE.

Given a 3SAT formula with clauses, build a graph as follows. Create three vertices per clause, labelled for clause . Connect two vertices and (with ) if their corresponding literals are compatible: the literal is not the negation of .

Claim: is satisfiable iff has a clique of size .

If is satisfiable, each clause has at least one true literal. Pick one true literal per clause. The corresponding vertices form a clique: any two of them are from different clauses, and their literals are both true under the satisfying assignment, so they cannot be negations of each other.

If has a clique of size , then the clique contains one vertex per clause (since there are no edges within a clause group). Set each literal in the clique to true. Since clique vertices are compatible, no literal contradicts another. Assign remaining variables arbitrarily. This satisfies .

Example: . The graph has 6 vertices. Vertex connects to and but not to (conflict). Vertex connects to , , and . Setting satisfies . The corresponding clique picks and (or other valid pairs).

Check your understanding Beginner

Formal definition Intermediate+

Definition (NP-completeness). A language is NP-complete if:

  1. .
  2. For every , (every NP problem polynomial-time reduces to ).

Theorem (Cook-Levin). SAT is NP-complete.

The proof constructs, for any NP machine and input , a Boolean formula of size polynomial in such that is satisfiable iff accepts . The formula encodes the entire computation tableau: rows are time steps, columns are tape cells, and variables indicate that cell at time contains symbol . Clauses enforce: (a) a valid start configuration, (b) each cell has exactly one symbol, (c) each window of three consecutive cells transitions correctly according to 's transition function, and (d) some cell contains an accept state [Sipser §7.4].

Reduction 1: SAT to 3SAT. Given a SAT instance , convert each clause with into a chain of 3-literal clauses using fresh variables :

.

This gadget is satisfiable iff the original clause is. The reduction produces a 3CNF formula of size .

Reduction 2: 3SAT to CLIQUE. Given a 3CNF formula with clauses, construct the graph described in the worked example. The graph has vertices and at most edges. has a -clique iff is satisfiable.

Reduction 3: CLIQUE to VERTEX-COVER. has a clique of size iff (the complement graph) has a vertex cover of size . The complement is computable in polynomial time.

Counterexamples to common slips

  • "NP means 'not polynomial.'" NP stands for Nondeterministic Polynomial time. It is the class of problems solvable in polynomial time on a nondeterministic machine. Many NP problems have no known polynomial-time algorithm, but NP does not mean "hard."

  • "NP-complete means 'the hardest problem there is.'" NP-complete means the hardest problem in NP. There are much harder problems outside NP (e.g., the halting problem, which is undecidable).

  • "A reduction from A to B means A and B are equally hard." A reduction means B is at least as hard as A. B could be harder. NP-completeness of B means B is at least as hard as every NP problem.

Key theorem with proof Intermediate+

Theorem (3SAT to HAM-CYCLE reduction). 3SAT HAM-CYCLE.

Proof sketch. Given a 3CNF formula with variables and clauses, construct a graph with a Hamiltonian cycle iff is satisfiable. The construction uses two types of gadgets.

Variable gadget. For each variable , create a diamond-shaped subgraph of 12 vertices arranged so that a Hamiltonian cycle traversing this subgraph must go either left-to-right (encoding ) or right-to-left (encoding ).

Clause gadget. For each clause , create a single node. This node can be visited by the Hamiltonian cycle only by "detouring" through the variable gadget corresponding to a literal in that is set to true. If appears positively in , the detour uses the rightward path through the gadget; if appears, it uses the leftward path.

The graph has vertices and edges, and the construction is polynomial. A Hamiltonian cycle in corresponds to a consistent truth assignment that satisfies every clause, and vice versa.

Bridge. The chain of reductions from SAT through 3SAT, CLIQUE, VERTEX-COVER, and HAM-CYCLE builds toward the entire theory of NP-completeness as a unified phenomenon: all NP-complete problems are polynomial-time equivalent, and this is exactly the foundational reason that resolving P vs NP for any one of them resolves it for all. The reductions appear again in 47.02.04 where the polynomial hierarchy layers additional quantifier alternations on top of NP, and in 47.04.04 where bipartite matching provides a contrasting example of a graph problem that sits firmly in P. The central insight is that the reduction is a constructive encoding of one problem's structure into another's, and this is exactly what makes NP-completeness a robust and transferable notion. Putting these together with the Cook-Levin theorem shows that SAT is the universal NP problem: every NP computation can be encoded as a Boolean formula, and from there, translated into the language of graphs, numbers, or any other NP-complete domain.

Exercises Intermediate+

Lean formalization Intermediate+

Mathlib has no formalisation of NP-completeness, the Cook-Levin theorem, or polynomial-time reductions between specific problems. The foundational gap is the absence of a verified reduction framework: a Complexity.PolynomialReduction structure with transitivity, and concrete instances for SAT-to-3SAT, 3SAT-to-CLIQUE, and CLIQUE-to-VERTEX-COVER. The Cook-Levin construction would require formalising the tableau encoding and the clause-generation algorithm. This unit ships without a lean_module.

Advanced results Master

Three directions extend the NP-completeness landscape.

Theorem 1 (thousands of NP-complete problems). Garey and Johnson's 1979 catalogue Computers and Intractability lists over 300 NP-complete problems across graph theory, number theory, algebra, combinatorics, and logic [Sipser §7.5]. The catalogue demonstrates that NP-completeness is not a rare property but a pervasive feature of combinatorial problems. Key additions include: 3-COLORING (chromatic number at most 3), KNAPSACK (the optimisation version of SUBSET-SUM), and LONGEST-PATH (does the graph have a simple path of length ?).

Theorem 2 (strong NP-completeness). A problem is strongly NP-complete if it remains NP-complete even when all numerical inputs are bounded by a polynomial in the input length. SUBSET-SUM is NP-complete but not strongly NP-complete (it has a pseudopolynomial dynamic programming algorithm). 3-PARTITION (can numbers be partitioned into triples of equal sum?) is strongly NP-complete. The distinction matters for approximation: problems that are not strongly NP-complete often have efficient approximation schemes [CLRS §34.5].

Theorem 3 (NP-completeness of approximate counting). Approximating the number of satisfying assignments of a SAT formula to within a factor of for any is NP-hard. This connects NP-completeness to the counting class studied in 47.02.07, where the exact counting version of SAT (SAT) is -complete by Toda's theorem.

Synthesis. The collection of NP-complete problems is the foundational reason that P-vs-NP is the central question of computational complexity: the central insight is that thousands of seemingly different problems across mathematics and computer science are connected by a web of polynomial-time reductions, and this is exactly what makes a positive resolution of P-vs-NP so impactful. This builds toward the polynomial hierarchy in 47.02.04 where the NP level is extended by alternating quantifiers, and it appears again in 47.03.05 where the PCP theorem characterises NP by probabilistic proof checking. The generalises from individual reductions to a structural theory of computational hardness, and putting these together with the approximation results shows that NP-completeness has consequences even when we relax the requirement of exact solutions.

Full proof set Master

Proposition 1 (SAT to 3SAT reduction correctness). The standard clause-splitting reduction converts a SAT instance to a 3SAT instance such that is satisfiable iff is satisfiable.

Proof. For each clause with , replace with the gadget using fresh variables .

Forward: if is satisfied by some , set and . Clause for is satisfied by ; clause (if it exists) is satisfied by ; clauses are satisfied by .

Backward: if the gadget is satisfied, at least one must be true. If all were false, then (from the first clause), (from the second), ..., . But the last clause would be , a contradiction.

Proposition 2 (CLIQUE to VERTEX-COVER reduction). has a clique of size iff has a vertex cover of size .

Proof. is a clique in iff every pair in has an edge in iff no pair in has a non-edge in iff every non-edge of has at least one endpoint in iff is a vertex cover of (since non-edges of are edges of ). The sizes match: .

Connections Master

  • 47.02.01 — The definitions of P, NP, and polynomial-time reductions provide the framework in which NP-completeness is defined.

  • 47.02.02 — The Cook-Levin theorem (SAT is NP-complete) is the starting point for all NP-completeness proofs; every reduction chain begins with SAT.

  • 47.02.04 — The polynomial hierarchy extends NP by alternating quantifiers; NP-complete problems are the base level .

  • 47.04.04 — Bipartite matching is in P, contrasting with the NP-completeness of Hamiltonian cycle on general graphs.

  • 47.02.07 — The counting class asks how many solutions an NP problem has; SAT (count satisfying assignments) is -complete.

Historical & philosophical context Master

Stephen Cook proved the NP-completeness of SAT in his 1971 paper "The Complexity of Theorem-Proving Procedures," presented at the ACM Symposium on Theory of Computing. He showed that any problem in NP can be encoded as a Boolean satisfiability problem, establishing SAT as the canonical NP-complete problem. Leonid Levin independently proved the same result in 1973 in the Soviet Union [Sipser §7.4].

Richard Karp's 1972 paper "Reducibility Among Combinatorial Problems" transformed Cook's result from an isolated theorem into a practical tool. Karp showed that 21 fundamental problems — including CLIQUE, VERTEX-COVER, HAM-CYCLE, SUBSET-SUM, and 3-COLORING — are all NP-complete. His paper established the reduction methodology as the standard technique for proving NP-completeness and created the first map of the NP-complete landscape.

Garey and Johnson's 1979 book Computers and Intractability: A Guide to the Theory of NP-Completeness systematised the field, providing a catalogue of over 300 NP-complete problems and a standard format for NP-completeness proofs. Their appendix listing known NP-complete problems by problem domain remains a standard reference.

The philosophical significance of NP-completeness lies in the observation that many problems arising naturally in engineering, operations research, and mathematics are equivalent in difficulty to SAT. This provides strong evidence that P NP, because resolving any one of these problems would resolve all of them simultaneously.

Bibliography Master

@book{sipser2013,
  author    = {Sipser, Michael},
  title     = {Introduction to the Theory of Computation},
  edition   = {3rd},
  publisher = {Cengage Learning},
  year      = {2013},
}
@book{clrs2022,
  author    = {Cormen, Thomas H. and Leiserson, Charles E. and Rivest, Ronald L. and Stein, Clifford},
  title     = {Introduction to Algorithms},
  edition   = {4th},
  publisher = {MIT Press},
  year      = {2022},
}
@inproceedings{cook1971complexity,
  author    = {Cook, Stephen A.},
  title     = {The Complexity of Theorem-Proving Procedures},
  booktitle = {Proceedings of the 3rd ACM Symposium on Theory of Computing},
  pages     = {151--158},
  year      = {1971},
}
@article{karp1972reducibility,
  author  = {Karp, Richard M.},
  title   = {Reducibility Among Combinatorial Problems},
  journal = {Complexity of Computer Computations},
  pages   = {85--103},
  year    = {1972},
  publisher = {Plenum Press},
}
@book{garey1979computers,
  author    = {Garey, Michael R. and Johnson, David S.},
  title     = {Computers and Intractability: A Guide to the Theory of NP-Completeness},
  publisher = {W. H. Freeman},
  year      = {1979},
}