4.6.26Theory of Computation

NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

2,731 words12 min readdifficulty · medium2 backlinks

What is NP-complete? (the 3 ingredients)

The reduction tool — HOW we prove hardness

Cook–Levin theorem (SAT is NP-complete) is the seed: it shows every NP problem reduces to SAT directly from the Turing-machine definition. After that, all other problems are proven hard by reducing from an already-proven NP-complete problem. The classic chain:

SATp3-SATpCliquepVertex CoverpHamiltonian CyclepTSP\text{SAT} \le_p \text{3-SAT} \le_p \text{Clique} \le_p \text{Vertex Cover} \le_p \text{Hamiltonian Cycle} \le_p \text{TSP} 3-SATpSubset Sum\text{3-SAT} \le_p \text{Subset Sum}

Figure — NP-complete problems — 3-SAT, Vertex Cover, Clique, Hamiltonian Path, TSP, Subset Sum

The cast of problems (definitions you must own)


Derivation 1 — Clique ↔ Vertex Cover ↔ Independent Set (the easy trio)


Derivation 2 — 3-SAT p\le_p Clique (the famous gadget)


Derivation 3 — 3-SAT p\le_p Subset Sum (number gadget)


Derivation 4 — Hamiltonian Cycle p\le_p TSP


Common mistakes (Steel-man + fix)


Flashcards

What does NP stand for and mean?
Nondeterministic Polynomial — a certificate can be verified in polynomial time.
Define NP-complete.
A problem that is both in NP and NP-hard (every NP problem reduces to it in poly time).
To prove problem BB is NP-hard, which direction is the reduction?
Reduce a known NP-complete problem AA into BB: ApBA \le_p B.
What does ApBA \le_p B guarantee?
xA    f(x)Bx\in A \iff f(x)\in B with ff poly-time; a fast solver for BB gives one for AA.
Which theorem first established an NP-complete problem?
Cook–Levin theorem (SAT is NP-complete).
Relation between Independent Set and Vertex Cover?
II independent of size kk     \iff VIV\setminus I is a vertex cover of size nkn-k.
Clique vs Independent Set link?
Clique in GG     \iff Independent Set in complement graph Gˉ\bar G.
In 3-SAT→Clique, when is there an edge between two literal-vertices?
Different clauses AND not negations of each other; clique size k=mk=m.
Why isn't Subset Sum's O(nt)O(nt) DP a poly-time algorithm?
tt has logt\log t bits, so tt can be exponential in input length → pseudo-polynomial.
In HamCycle→TSP, what edge weights and budget are used?
Weight 1 for real edges, 2 otherwise; budget B=VB=|V| (a tour is a cycle with V|V| edges).
Why is the TSP budget V|V| and not V1|V|-1?
A TSP tour is a cycle returning to start, so it has V|V| edges, not V1|V|-1 like a path.
Is NP-complete the same as undecidable?
No — NP-complete problems are decidable (brute force terminates); just (likely) not poly-time.
Decision form of TSP?
Given weighted complete graph and budget BB, is there a tour (cycle) of total cost B\le B?

Recall Feynman: explain to a 12-year-old

Imagine a huge group of puzzles — Sudoku, mazes, packing suitcases. They all look different, but there's a secret machine that can turn any one puzzle into any other. So they're really one giant puzzle in disguises. We don't know a quick trick to solve them, but if you finish one, we can check your answer super fast. And the wild part: if someone ever finds a fast trick for just one, the machine instantly gives a fast trick for all of them. These disguised twins are called NP-complete.

Connections

  • P vs NP — the open million-dollar question these problems define.
  • Cook–Levin Theorem — the seed of all NP-completeness proofs.
  • Polynomial-time Reductions — the proof machinery.
  • Boolean Satisfiability (SAT, CNF) — root of the reduction tree.
  • Graph Theory — Cliques and Independent Sets
  • Dynamic Programming — Subset Sum / Knapsack (pseudo-polynomial).
  • Approximation Algorithms — what we do when exact is hopeless (e.g. 2-approx Vertex Cover).
  • Undecidability and the Halting Problem — a stronger kind of impossibility.

Concept Map

plus

both give

both give

proves

seeds chain

reduces to

reduces to

complement

links

reduces to

reduces to

reduces to

reduces to

NP - verify in poly time

NP-hard - all NP reduces to it

NP-complete

Poly-time reduction A le B

Cook-Levin - SAT NP-complete

SAT

3-SAT

Clique

Vertex Cover

Independent Set helper

Hamiltonian Cycle

TSP decision

Subset Sum

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, NP-complete problems basically ek hi gang ke members hain jo alag-alag costume pehne hue hain. 3-SAT, Clique, Vertex Cover, Hamiltonian Cycle/Path, TSP, Subset Sum — yeh sab apparently bohot hard lagte hain (koi fast solution nahi pata), par inki ek khaas baat hai: agar koi tumhe answer de de, to tum usse polynomial time mein verify kar sakte ho. Isi ko NP kehte hain — "verify karna easy, dhoondhna hard". Aur NP-complete matlab yeh NP ke andar ke sabse hard problems hain. (Independent Set ek helper twin hai jo Clique aur Vertex Cover ko jodta hai.)

Asli jaadu hai reduction. Reduction ek fast translator hai: ApBA \le_p B ka matlab — agar BB ka fast solver mil jaaye, to AA bhi fast solve ho jaayega. Toh hardness prove karne ka rule yaad rakho: naye problem BB ko hard dikhane ke liye, kisi already-known hard problem ko BB ke andar feed karo. Direction ulta mat karna — yeh sabse common galti hai! Cook–Levin theorem ne sabse pehle SAT ko NP-complete prove kiya, aur baaki sab usi se chain banake prove hue.

Ek important trap: Subset Sum ka O(nt)O(n \cdot t) DP dekh ke lagta hai "are yeh to polynomial hai!" — par nahi. Target tt ek number hai jiski length sirf logt\log t bits hai, toh tt input ke size mein exponential ho sakta hai. Isko pseudo-polynomial kehte hain. Aur ek aur dhyaan dene wali baat — TSP ka tour ek cycle hota hai (start pe wapas aata hai), isliye usme nn edges hote hain, n1n-1 nahi. Isiliye HamCycle→TSP reduction mein budget B=nB=n rakhte hain, n1n-1 nahi. Yeh poora khel P vs NP ke million-dollar question ke center mein hai, aur NP-complete ka matlab undecidable nahi — yeh solve to ho jaate hain brute force se, bas fast nahi.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections