A Bit of History
Stephen Cook published "The Complexity of Theorem-Proving Procedures" in 1971, proving that Boolean satisfiability (SAT) is NP-complete — the founding result of computational complexity theory. Leonid Levin, working independently in the Soviet Union under very different political and academic constraints, discovered an equivalent result around the same time, published in 1973 — the theorem is now properly called the Cook-Levin theorem in recognition of both. The very next year, Richard Karp (whose name recurs throughout this series, from Edmonds-Karp to Held-Karp) published "Reducibility Among Combinatorial Problems" in 1972, showing 21 fundamental combinatorial problems — many of them graph problems already met in this series — are all NP-complete, cementing the theory's practical relevance to real algorithmic questions almost immediately.
NP-Hardness of Graph Problems
A problem is in NP if a proposed solution can be verified quickly (in polynomial time), even if finding one might be hard. A problem is NP-complete if it is in NP and every other NP problem can be efficiently transformed ("reduced") into it — meaning an efficient algorithm for one NP-complete problem would efficiently solve all of them. Whether \(P = NP\) remains the most famous open problem in computer science.
Four Labels, Four Different Claims
The names are easy to blur together, so separate the question each label answers. Complexity classes are mostly discussed for decision problems — yes/no questions. An optimization problem such as "find the smallest vertex cover" is usually called NP-hard, while its threshold decision version — "is there a vertex cover of size at most \(k\)?" — can be NP-complete.
Do Not Memorize a Venn Diagram — Memorize the Question
Each label says something different about solving, checking, or being at least as hard as other problems.
Think in Terms of Certificates
For Hamiltonian Cycle, a certificate is simply the proposed cyclic ordering of the vertices. Verification is easy: check that every vertex appears once, consecutive vertices are adjacent, and the final vertex reconnects to the first. The difficult part is discovering such a certificate when one exists.
Reductions: How Hardness Moves Between Problems
A polynomial-time reduction \(A \le_p B\) is an efficient translator: it converts every instance of problem \(A\) into an instance of problem \(B\) so that solving the translated instance answers the original question. The direction matters enormously. To prove a new problem \(B\) is hard, start from a problem \(A\) already known to be hard and show \(A \le_p B\).
A Reduction Is a Translator, Not a Similarity Claim
Classic Reduction Mistake
Showing \(B \le_p A\) does not prove \(B\) is hard when \(A\) is hard. It only says an algorithm for \(A\) could solve \(B\). For a hardness proof, reduce from a known-hard problem to the new problem.
Karp's 21 NP-Complete Problems
Several of Karp's original 21 problems are graph problems this series has directly encountered:
- Hamiltonian Cycle (Part 12) — deciding whether a Hamiltonian cycle exists is NP-complete, in sharp contrast to the Eulerian circuit case, which Hierholzer's algorithm solves in linear time. This single contrast is one of the most-cited examples in complexity theory of how superficially similar problems can have wildly different difficulty.
- Graph Coloring (deciding if a graph is 3-colorable, generalizing Part 13) — NP-complete, even though 2-colorability (bipartiteness) is solvable in linear time via BFS.
- Clique (deciding whether a graph contains a complete subgraph of a given size) — NP-complete, and closely tied to the independent set and vertex cover problems by simple graph-complement reductions.
- Vertex Cover (finding the smallest set of vertices touching every edge) — NP-complete, though it admits a simple factor-2 approximation and is famously fixed-parameter tractable in the cover size (connecting to treewidth ideas from Part 18).
The Traveling Salesman Problem (Part 14) is likewise NP-hard (its decision version, "is there a tour of cost at most \(k\)", is NP-complete), directly motivating the exact-but-exponential Held-Karp algorithm and the polynomial-but-approximate Christofides algorithm from recent deep dives.
Tiny Wording Changes Can Cross a Huge Complexity Boundary
The difficult part is often not the graph itself, but the exact question being asked about it.
Restriction Can Change Everything
An NP-hard problem can become easy on a structured graph family: coloring is efficient on chordal graphs, many hard problems become tractable on bounded-treewidth graphs, and matching is especially efficient on bipartite graphs. “Hard in general” never means “every instance is hard.”
Matroid Theory
Hassler Whitney introduced matroids in 1935, abstracting the essential combinatorial structure shared by linear independence in vector spaces and cycle-free edge sets in graphs. A matroid is a pair \((E, \mathcal{I})\): a ground set \(E\) and a family \(\mathcal{I}\) of subsets declared "independent." The power comes from three compact rules.
The first two say independence is downward-closed. The third — the exchange axiom — is the real engine: if one independent solution is smaller than another, there is always some element from the larger one that safely extends the smaller one. That “you can always make locally safe progress” property is exactly what greedy algorithms need.
A Forest Is an Independent Set of Edges
Why Greedy Becomes Universally Safe
For a weighted matroid, the standard greedy algorithm — process elements from best weight to worst and keep an element whenever independence is preserved — produces an optimal basis. Kruskal’s MST algorithm is exactly this theorem applied to the graphic matroid: sort edges by increasing weight and keep an edge when it does not create a cycle.
The Real Lesson of Matroids
Greedy is not magically reliable. It is reliable when the feasible sets have enough exchange structure. Matroids isolate exactly one broad setting where local “best safe choice” decisions are guaranteed to assemble into a globally optimal basis.
Edmonds also developed polynomial-time matroid intersection algorithms, which seek a largest set independent in two matroids at once. This creates a powerful unifying framework for problems that look unrelated at first glance.
Approximation Algorithms
Since exact polynomial-time algorithms for NP-hard problems are not believed to exist, approximation algorithms trade exactness for speed while keeping a mathematical contract on solution quality. That contract is what separates an approximation algorithm from a heuristic: a heuristic may work very well in practice; an approximation algorithm comes with a worst-case guarantee.
Approximation Ratios: Turn “Pretty Good” into an Inequality
For a minimization problem, an \(\alpha\)-approximation guarantees that the algorithm’s cost is at most \(\alpha\) times optimal. For a maximization problem, the direction reverses.
Why the Maximal-Matching Vertex-Cover Algorithm Is a 2-Approximation
Take any maximal matching \(M\), then put both endpoints of every matched edge into the cover. The selected vertices certainly cover every edge; otherwise an uncovered edge could be added to the matching, contradicting maximality.
Formal approximation families include:
- Constant-factor approximation: guarantees within a fixed factor of optimal, such as factor 2 for the vertex-cover method above or \(3/2\) for Christofides on metric TSP.
- PTAS (Polynomial-Time Approximation Scheme): for any desired accuracy \(\epsilon>0\), produces a \((1+\epsilon)\)-approximation in time polynomial in the input size for each fixed \(\epsilon\), though the dependence on \(1/\epsilon\) may be very expensive.
- FPTAS (Fully Polynomial-Time Approximation Scheme): polynomial in both the input size and \(1/\epsilon\).
PTAS vs. FPTAS
Both let you ask for more accuracy. The difference is the price of that accuracy: a PTAS may become impractical extremely quickly as \(\epsilon\) shrinks, while an FPTAS requires the runtime to remain polynomial in \(1/\epsilon\) as well.
Not every NP-hard problem admits even a constant-factor approximation. General TSP without the triangle inequality cannot be approximated within any fixed constant factor in polynomial time unless \(P=NP\). Approximation itself therefore has a complexity theory: some problems are hard to solve exactly but easy to approximate; others remain resistant even when we relax optimality.
When Exact Is Hard, Change the Question You Ask
NP-hardness is not a command to give up. It tells you which escape hatches to look for: small inputs, special graph structure, a small parameter, an approximation guarantee, or a heuristic that performs well empirically.
A Practical Toolkit for Hard Graph Problems
Fixed-parameter tractability is especially useful when a natural parameter \(k\) is small even though the graph itself is large. Vertex Cover parameterized by solution size is a classic example: the exponential dependence can be isolated in \(k\) while the dependence on the full input remains polynomial.
Real-World Applications
Chip Design & Register Allocation Reductions
Compiler register allocation (previewed as a graph-coloring application in Part 13) and VLSI placement/routing contain NP-hard optimization subproblems. Production systems therefore combine multiple ideas from this part: exploit special structure when it appears, solve small subinstances exactly, use approximation or relaxation when guarantees are available, and fall back to high-quality heuristics when worst-case guarantees would be too expensive.
- P
Solve efficiently. - NP
Verify a yes-certificate efficiently. - Reduction
Translate one problem into another. - NP-complete
In NP and NP-hard. - Matroid
Exchange structure makes greedy safe. - Approximation
Trade exactness for a provable ratio. - FPT
Push combinatorial explosion into a small parameter. - Heuristic
Fast practical strategy without a universal ratio guarantee.
Exercises
- Explain why "is there a Hamiltonian cycle in this graph" is in NP (i.e., why a proposed cycle can be verified quickly), even though finding one appears to require exponential search.
- Verify the matroid axioms hold for the graphic matroid of a small graph, by checking that every subset of a forest is itself a forest, and that any non-maximal forest can be extended by adding one more edge.
- Explain in your own words why the factor-2 vertex cover approximation (take both endpoints of every edge in a maximal matching) is guaranteed to never be more than twice the optimal cover size.
- Challenge: Research why general (non-metric) TSP cannot be approximated to any constant factor in polynomial time unless \(P=NP\), by looking up the "gadget" reduction argument from an NP-hard problem like Hamiltonian Cycle.
Conclusion & Next Steps
Complexity theory explains why so many algorithms in this series settled for heuristics or approximations rather than exact solutions — and matroid theory reveals the surprising unity behind why greedy algorithms like Kruskal's and Prim's work at all. The series now turns to how graph algorithms scale to genuinely massive, real-world data — data too large to fit on one machine, or arriving too fast to store in full.
Next in the Series
In Part 23: Modern Graph Algorithms — Dynamic, Streaming & Distributed, we'll explore how graph algorithms adapt to massive, changing, and distributed data.