Back to Graph Theory Series

Part 22: Complexity, Approximation & Combinatorial Optimization

September 13, 2026 Wasil Zafar 32 min read

One 1971 paper and one 1972 paper, together, revealed that dozens of graph problems this series has quietly avoided solving exactly are all, secretly, the same hard problem in disguise.

Table of Contents

  1. A Bit of History
  2. NP-Hardness of Graph Problems
  3. Karp's 21 NP-Complete Problems
  4. Matroid Theory
  5. Approximation Algorithms
  6. Real-World Applications
  7. Exercises
  8. Conclusion & Next Steps

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.

Complexity Map Decision problems

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.

P, NP, NP-hard, and NP-complete intuition Four cards explain that P means solvable in polynomial time, NP means a yes certificate is verifiable in polynomial time, NP-hard means every NP problem reduces to it, and NP-complete means both NP and NP-hard. Complexity labels answer different questions P Can we solve it quickly? Polynomial-time algorithm Examples: BFS, MST, bipartite testing solve + verify quickly NP Can we check a yes-proof? Polynomial-time verifier Certificate: cycle, coloring, clique, cover, ... P is contained in NP NP-hard Is it at least this hard? Every NP problem can be translated to it efficiently Need not itself be in NP hardness statement NP-complete Both claims at once 1. The problem is in NP 2. The problem is NP-hard A polytime solver here would imply P = NP NP + NP-hard Unknown: whether every efficiently verifiable problem is also efficiently solvable (P = NP?)
NP is about efficiently verifying a certificate; NP-hard is about reductions. NP-complete means both.

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 \le_p B \quad\text{and}\quad B\in P \quad\Longrightarrow\quad A\in P$$
Reduction Intuition Direction matters

A Reduction Is a Translator, Not a Similarity Claim

Polynomial-time reduction direction Known hard problem A is translated in polynomial time into target problem B. If B could be solved quickly, the solution could be decoded to solve A quickly. Therefore hardness transfers from A to B. To prove B is hard, translate a known-hard A into B Problem A already known hard instance x polytime translate Problem B target problem instance f(x) hypothetical fast solver Answer for B decode efficiently gives answer for A If B were easy, this whole loop would make A easy too
Hardness flows in the same direction as the reduction: known-hard \(A\) reduces to target \(B\).

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.

Complexity Boundary

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.

Polynomial versus NP-complete graph problem pairs Three rows contrast Eulerian circuit with Hamiltonian cycle, bipartite testing with 3-colorability, and shortest path with traveling salesman optimization. Similar-sounding questions can have radically different difficulty Efficiently solvable NP-complete / NP-hard Use every edge once Eulerian circuit: degree test + Hierholzer Visit every vertex once Hamiltonian cycle: NP-complete Can 2 colors suffice? Bipartite test: BFS / DFS Can 3 colors suffice? 3-colorability: NP-complete Cheapest path from s to t Shortest path: polynomial time Cheapest tour through all vertices TSP optimization: NP-hard
Complexity is a property of a precisely defined problem, not of a topic such as “paths” or “coloring” in general.

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.

$$\varnothing\in\mathcal I$$ $$A\in\mathcal I,\; B\subseteq A \Longrightarrow B\in\mathcal I$$ $$A,B\in\mathcal I,\; |A|<|B| \Longrightarrow \exists e\in B\setminus A:\; A\cup\{e\}\in\mathcal I$$

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.

Graphic Matroid Independent = acyclic

A Forest Is an Independent Set of Edges

Graphic matroid and exchange intuition A weighted graph shows a selected forest, a cycle-forming edge that must be rejected, and an exchange step showing how a smaller forest can take a safe edge from a larger forest. Graphic matroid: independent edge sets are exactly forests Greedy selection: keep an edge only if no cycle appears would close a cycle A B C D E Selected teal edges stay independent Exchange axiom: a larger forest can safely donate an edge Smaller A Larger B add one Because |A| < |B|, some edge in B - A extends A without creating a cycle
In a graphic matroid, “independent” simply means “contains no cycle.”

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.

$$\text{minimization: }\quad \mathrm{ALG}(I) \le \alpha\,\mathrm{OPT}(I)$$ $$\text{maximization: }\quad \mathrm{ALG}(I) \ge \frac{\mathrm{OPT}(I)}{\alpha}$$
Guarantee Vertex Cover

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.

Factor two vertex cover approximation from a maximal matching A graph contains three disjoint matched edges. Both endpoints of those edges produce a cover of size six. Any vertex cover must contain at least one endpoint of each matched edge, so optimum is at least three and the algorithm is at most twice optimum. Maximal matching gives both a solution and a lower bound Three matched edges: |M| = 3 Algorithm picks all 6 blue vertices The inequality behind the ratio Every cover needs >= 1 endpoint from each matched edge OPT >= |M| = 3 ALG = 2|M| = 6 ALG <= 2 x OPT
The matching is both a construction tool and a certificate that the optimum cannot be smaller than \(|M|\).

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.

Strategy Map

A Practical Toolkit for Hard Graph Problems

Strategy map for NP-hard graph problems A central hard problem branches to exact exponential algorithms for small inputs, exploiting special structure, fixed-parameter algorithms, approximation algorithms, and heuristics. NP-hard does not mean “nothing useful can be done” Hard problem instance Which compromise fits the application? Exact exponential Small n? DP, branch-and-bound, integer programming Keep optimality Exploit structure Special family? Bipartite, chordal, planar, low treewidth Hard general, easy here Parameterize Small parameter k? FPT runtime: f(k) times poly(n) Move explosion into k Approximate Need a guarantee? Constant factor, PTAS, FPTAS Relax optimality Heuristic Need speed most? Local search, greedy, metaheuristics Empirical quality Complexity theory helps you choose the right compromise instead of searching blindly for a nonexistent silver bullet
“NP-hard” describes worst-case exact complexity. Real algorithm design asks which extra assumption or compromise is available.
$$\text{FPT form:}\qquad T(n,k)=f(k)\,n^{O(1)}$$

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

Case Study

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.

Compiler DesignVLSI
Part 22 Mental Model
  • 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.