Approximation Algorithms
Some problems are so hard that finding the exact optimal solution would take longer than the age of the universe — even on the fastest computer. These are the NP-hard problems. So what do you do?
You don't give up. You use an approximation algorithm: a fast algorithm that comes with a provable promise that its answer is never too far from optimal. Not a guess — a mathematical guarantee.
The approximation ratio
An algorithm has approximation ratio α if it always returns a solution within factor α of optimal:
• For minimization: algorithm's answer ≤ α × OPT (α ≥ 1).
• For maximization: algorithm's answer ≥ OPT / α (α ≥ 1).
A ratio of 2 means you're at most twice the optimal cost. A ratio of 1.5 means you're at most 50% above optimal. The closer to 1, the better.
Vertex Cover — the elegant 2-approximation
A vertex cover is a set of vertices S such that every edge has at least one endpoint in S. (Think: placing guards at intersections so every road is watched.) Finding the minimum vertex cover is NP-hard.
The 2-approximation: repeatedly pick any uncovered edge (u, v), add both u and v to the cover, remove all edges incident to either. Repeat until no edges remain. Done in \(O(V+E)\).
Why is this at most 2× optimal? The edges we pick form a matching — no two share a vertex. Our cover takes 2 vertices per selected edge. Any valid cover must include at least 1 vertex per selected edge (to cover it). So |OUR COVER| ≤ 2 × |OPT|.
Metric TSP — Christofides 1.5-approximation
The Traveling Salesman Problem on metric distances (triangle inequality: no shortcut is longer than the path through a third city) admits a beautiful 1.5-approximation:
1. Find a minimum spanning tree T of all cities.
2. Identify the set O of vertices with odd degree in T (always an even count by the handshaking lemma).
3. Find a minimum weight perfect matching M on those odd-degree vertices.
4. Combine T and M into an Eulerian multigraph (every vertex now has even degree).
5. Find an Euler circuit, then shortcut repeated cities (triangle inequality guarantees shortcuts never increase cost).
The result is a tour of cost at most 1.5 × OPT.
Set Cover — the greedy \(O(\log n)\)-approximation
Given a universe of n elements and a collection of sets, find the fewest sets that cover everything. Greedy: always pick the set that covers the most currently uncovered elements. Repeat until everything is covered.
This achieves approximation ratio H_n = 1 + 1/2 + 1/3 + … + 1/n ≈ ln(n). And here's the kicker: no polynomial-time algorithm can do better (unless P=NP). The greedy algorithm is essentially optimal among all efficient algorithms.
PTAS and FPTAS
A Polynomial-Time Approximation Scheme (PTAS) gives you a (1+ε)-approximation for any ε you choose — closer to optimal for smaller ε, but potentially slower. A Fully Polynomial-Time Approximation Scheme (FPTAS) must run in time polynomial in both n and 1/ε — making even tiny ε practical. The 0/1 Knapsack problem has an FPTAS: scale and round item values, then run exact DP, giving a (1+ε)-approximation in \(O(n^2/ε)\) time.