Sub topic 1
Why NP-Hard Optimization Calls for Approximation
Prerequisites
This chapter assumes you know Big-O notation, basic graph terms (vertex, edge, matching), what NP-completeness means, and how to read simple Python.
The Cost of Exactness
Many practical optimization problems are NP-hard. These include choosing the fewest servers to monitor every network link, scheduling jobs, and routing vehicles. Unless P = NP, no polynomial-time algorithm solves them exactly. Exact methods such as brute force or branch-and-bound can take exponential time in the worst case. An approximation algorithm runs in polynomial time and returns a solution with a proven bound on how far it can be from the optimum.
Approximation Ratios
Let OPT be the optimal value on an instance and ALG the value the algorithm returns.
| Problem type | Guarantee | Ratio range |
|---|---|---|
| Minimization | ALG ≤ ρ · OPT | ρ ≥ 1 |
| Maximization | ALG ≥ ρ · OPT | ρ ≤ 1 |
The bound must hold on every input, not just on average. A common error is to read "2-approximation" as "usually twice optimal." In fact it means "never worse than twice optimal."
Bounding the Unknown Optimum
You cannot compute OPT, so you cannot compare against it directly. The standard method has three steps:
- Find a quantity L that you can compute, with L ≤ OPT (for minimization).
- Show that ALG ≤ ρ · L.
- Conclude that ALG ≤ ρ · OPT.
A 2-Approximation for Vertex Cover
A vertex cover is a set of vertices that touches every edge. The algorithm scans the edges. Whenever an edge has neither endpoint in the cover, it adds both endpoints.
def vertex_cover_2approx(edges):
cover = set()
for u, v in edges:
if u not in cover and v not in cover:
cover.add(u)
cover.add(v)
return cover
print(vertex_cover_2approx([(0, 1), (1, 2), (2, 3), (3, 0)]))On the 4-cycle it prints {0, 1, 2, 3}. The optimum is {0, 2}, so the ratio of 2 is reached exactly here.
Proof. The edges that trigger an addition share no endpoints, so together they form a maximal matching M. Any cover must include at least one endpoint of each edge in M, which gives OPT ≥ |M|. The algorithm adds exactly 2|M| vertices, so ALG = 2|M| ≤ 2 · OPT. Here |M| plays the role of the lower bound L.
Exercise
Run the algorithm on the path with edges (0,1), (1,2), (2,3), processed in that order. What cover does it return, what is the optimum, and which lower bound proves the ratio?
Show answer
It returns {0, 1, 2, 3}. The edge (1,2) is skipped because 1 is already in the cover. The optimum is {1, 2}, with size 2. The matching {(0,1), (2,3)} has size 2, so OPT ≥ 2 and ALG = 4 ≤ 2 · OPT.