Algorithms Β· Complexity Theory
πŸ“… July 2026 ⏱ β‰ˆ 14 min read 🎯 Advanced Β· Last updated: 9 July 2026

NP-completeness: how SAT, 3-COLOR, and TSP are secretly the same problem

There is no known efficient algorithm for the Traveling Salesman Problem, graph coloring, or Boolean satisfiability β€” and it is not for lack of trying. Reductions are the proof technique that shows these problems are all, in a precise sense, the same problem wearing different disguises.

TL;DR: SAT, graph 3-coloring, and the Traveling Salesman Problem are all NP-complete, meaning they're secretly the same underlying problem in different disguises. Cook-Levin proves SAT is the seed case, and polynomial-time reductions carry that hardness on to 3-COLOR and TSP via Hamiltonian Cycle. No known algorithm solves any of them quickly, so real-world solvers rely on heuristics and approximations instead.

P, NP, and NP-hard

P is the class of decision problems solvable in polynomial time. NP is the class of decision problems whose solutions can be verified in polynomial time β€” even if finding one might take exponentially long. Every problem in P is trivially in NP (if you can solve it fast, you can verify a solution fast), but whether P = NP is the most famous open problem in computer science.

A problem is NP-hard if every problem in NP can be reduced to it in polynomial time β€” informally, it's "at least as hard as anything in NP." A problem that is both NP-hard and itself in NP is NP-complete.

P βŠ† NP    known
P = NP ?    open β€” a $1,000,000 Millennium Prize problem
NP-complete = NP ∩ NP-hard

Polynomial-time reductions

A polynomial-time reduction from problem A to problem B (written A β‰€β‚š B) is a polynomial-time algorithm that transforms any instance of A into an instance of B, such that the answer to B's instance tells you the answer to A's instance. The key logical consequence:

If A β‰€β‚š B and B ∈ P, then A ∈ P
Contrapositive: if A is NP-hard and A β‰€β‚š B, then B is NP-hard too
Reductions transmit hardness "forward" β€” this is how the entire web of NP-complete problems is built from one seed problem

This is exactly the strategy used to prove new problems are NP-complete: don't design an algorithm from scratch, instead show that a known NP-complete problem reduces to it.

Cook-Levin: SAT is NP-complete

The Cook-Levin theorem (1971) is the seed of the entire reduction tree: it proves that Boolean satisfiability (SAT) is NP-complete directly, by simulating an arbitrary polynomial-time nondeterministic Turing machine's computation history as a giant Boolean formula. Any accepting computation of the machine corresponds to a satisfying assignment, and vice versa.

3-SAT β€” where every clause has exactly 3 literals β€” is also NP-complete (SAT reduces to 3-SAT by splitting long clauses with auxiliary variables), and is the most common starting point for reductions because its uniform structure is easy to encode into other combinatorial problems.

3-SAT instance example:
(x₁ ∨ xΜ„β‚‚ ∨ x₃) ∧ (x̄₁ ∨ xβ‚‚ ∨ x̄₃) ∧ (xβ‚‚ ∨ x₃ ∨ x̄₁)
Question: does an assignment of x₁,xβ‚‚,x₃ ∈ {T,F} make every clause true?

Reducing 3-SAT to 3-COLOR

Graph 3-coloring asks: can the vertices of a graph be colored with 3 colors such that no edge connects two vertices of the same color? The classic reduction from 3-SAT builds three gadgets:

  1. Base triangle: three special vertices T (True), F (False), B (Base), mutually connected, fixing three distinct "reference colors."
  2. Variable gadget: for each variable xα΅’, a triangle {xα΅’, xΜ„α΅’, B} forces xα΅’ and xΜ„α΅’ to take the T or F color β€” but never the same one, exactly encoding "xα΅’ is true XOR xα΅’ is false."
  3. Clause gadget (OR-gadget): for each clause (a ∨ b ∨ c), a small 6-vertex gadget connected to literals a, b, c and to the T/F vertices, constructed so that it is 3-colorable if and only if at least one of a, b, c is colored T.
Reduction size: O(n + m) vertices for n variables, m clauses
3-SAT formula satisfiable ⟺ constructed graph is 3-colorable
Why this proves NP-hardness of 3-COLOR: the construction runs in polynomial time and preserves the yes/no answer exactly. So if we could 3-color any graph in polynomial time, we could solve 3-SAT in polynomial time too β€” which would imply P = NP. Since 3-COLOR is also verifiable in polynomial time (just check every edge), it is NP-complete.

Reducing 3-SAT to TSP (via Hamiltonian cycle)

The Traveling Salesman Problem (decision version: "is there a tour of length ≀ k?") is usually shown NP-hard in two steps: 3-SAT reduces to Hamiltonian Cycle (does a cycle visiting every vertex exactly once exist?), and Hamiltonian Cycle reduces trivially to TSP.

Step 1 β€” Hamiltonian Cycle reduces to TSP

Given a graph G, build a complete weighted graph G' on the same vertices: edges present in G get weight 1, all other edges get weight 2. G has a Hamiltonian cycle if and only if G' has a tour of total weight exactly n (using only weight-1 edges):

w'(u,v) = 1 if (u,v) ∈ E(G), else 2
TSP tour of weight n exists in G' ⟺ Hamiltonian cycle exists in G

Step 2 β€” 3-SAT reduces to Hamiltonian Cycle

This reduction (due to Karp, 1972) is intricate: each variable xα΅’ is represented by a "twisted ladder" gadget with two possible traversal directions (corresponding to xα΅’ = True or False), and each clause is represented by a connector vertex that can only be visited by "borrowing" a pass from one of its three literal gadgets β€” forcing at least one literal per clause to be traversed in the "satisfying" direction.

Reduction chainWhat it establishes
3-SAT β‰€β‚š Hamiltonian CycleHam. Cycle is NP-hard
Hamiltonian Cycle β‰€β‚š TSPTSP (decision) is NP-hard
TSP ∈ NPa candidate tour is checkable in O(n)
⟹ TSP is NP-complete

What NP-completeness means in practice

Proving a problem NP-complete is not a dead end β€” it's actionable information. It tells you:

Living with NP-hardness: heuristics

For instances too large for exact methods, practitioners reach for heuristics that trade optimality guarantees for speed:

ProblemCommon heuristicTypical quality
TSPNearest-neighbor + 2-opt~5% above optimal
TSPGenetic / Lin-Kernighan<1% above optimal
3-SATWalkSAT (local search)Solves most practical instances
Graph coloringGreedy + DSATUR orderingUsually within a few colors of optimal
No free lunch: every one of these heuristics can be made to perform arbitrarily badly on adversarially constructed inputs β€” this is itself a consequence of the underlying problem being NP-hard. Random or structured "real-world" instances are usually far more forgiving than worst-case theory suggests.
β–Ά Live Demo

🀝 Watch heuristics fight NP-hardness live

Compare greedy, 2-opt, and genetic algorithm solutions to the Traveling Salesman Problem

Open simulation β†’

πŸ”— Related Simulations

🀝TSP 🧬Genetic Algorithm 🧩N-Queens πŸ—ΊοΈPathfinding