15: Approximation Algorithms
Motivation and Approximation Ratios
When a problem is NP-hard, we abandon the requirement of exact optimality and instead seek solutions that are provably close to optimal. An approximation algorithm is a polynomial-time algorithm that returns a feasible solution whose cost is within a guaranteed factor of the optimum.
For a minimization problem, an algorithm has approximation ratio if for every instance of size , the algorithm’s cost satisfies , where is the optimal cost. For maximization, the condition is . In both cases , and a ratio closer to 1 indicates a tighter guarantee.
An approximation scheme is a family of algorithms parametrized by achieving ratio . A polynomial-time approximation scheme (PTAS) runs in time polynomial in for each fixed (but possibly exponential in ). A fully polynomial-time approximation scheme (FPTAS) runs in time polynomial in both and .
Vertex Cover: A 2-Approximation
Problem. Given an undirected graph , find a minimum-size set such that every edge has at least one endpoint in .
Algorithm (Maximal Matching). Repeatedly select an arbitrary uncovered edge , add both and to the cover, and remove all edges incident to or . Continue until no edges remain.
Analysis. Let be the set of edges selected. Since no two edges in share an endpoint (they form a matching), edges require at least distinct vertices in any vertex cover (each edge must be covered). The algorithm outputs vertices. Therefore the approximation ratio is:
This bound is tight: consider a complete bipartite graph . The algorithm may select all matching edges and return vertices, while the optimal cover has size . Improving the ratio below 2 for vertex cover is a major open problem; under the Unique Games Conjecture, no polynomial-time algorithm achieves a ratio better than .
Traveling Salesman Problem
Problem. Given a complete graph with edge weights satisfying the triangle inequality (), find a minimum-weight Hamiltonian cycle.
2-Approximation via MST
Compute a minimum spanning tree of . Since deleting any edge from an optimal tour yields a spanning tree, . Doubling every edge of gives an Eulerian graph whose total weight is . An Euler tour of this graph visits every vertex at least once; shortcutting repeated vertices (using the triangle inequality to ensure shortcuts do not increase cost) yields a Hamiltonian cycle of weight at most .
Christofides’ Algorithm: 3/2-Approximation
Christofides (1976) improves on the doubling approach:
- Compute a minimum spanning tree .
- Let be the set of odd-degree vertices in (by the handshaking lemma, is even).
- Find a minimum-weight perfect matching on the vertices in .
- Combine and to get an Eulerian multigraph (all vertices now have even degree).
- Find an Euler tour of and shortcut to a Hamiltonian cycle.
Analysis. We have . For the matching, consider the optimal tour restricted to vertices in : this defines a Hamiltonian cycle on of cost at most (by the triangle inequality, shortcuts only reduce cost). This cycle decomposes into two perfect matchings, each of weight at most . Since is a minimum matching, . Therefore:
For the general (non-metric) TSP, no constant-factor approximation exists unless .
Set Cover: Greedy Approximation
Problem. Given a universe of elements and a collection of subsets of , find the fewest subsets whose union is .
Greedy Algorithm. Repeatedly select the subset covering the most uncovered elements until is covered.
Theorem. The greedy algorithm achieves an approximation ratio of , where .
Proof sketch. Assign a cost of to each newly covered element when set is chosen (where is the set of already covered elements). If the optimal solution uses sets, then at each step, some set covers at least a fraction of remaining elements. A harmonic series argument shows the total greedy cost is at most .
This bound is essentially tight: under standard complexity assumptions, no polynomial-time algorithm achieves a ratio of for any .
Load Balancing
Problem. Assign jobs with processing times to identical machines to minimize the makespan (maximum load on any machine).
Greedy (List Scheduling). Assign each job to the currently least-loaded machine.
Analysis. Let be a lower bound on the optimal makespan. The greedy makespan satisfies , giving a 2-approximation. The Longest Processing Time (LPT) rule — sorting jobs in decreasing order before applying greedy — improves the ratio to .
PTAS and FPTAS
Knapsack FPTAS. The 0/1 knapsack problem admits an FPTAS. The idea is to scale and round the item values: divide each value by a factor , round down to integers, and solve the resulting problem exactly via dynamic programming in time. The rounding introduces at most total error, so the solution is within a factor of optimal.
Not all NP-hard problems admit a PTAS. Under appropriate complexity assumptions, problems like general TSP, graph coloring, and maximum clique have no constant-factor approximation, let alone a PTAS.
Inapproximability
The PCP theorem (Arora et al., 1998) establishes that certain problems cannot be approximated beyond specific thresholds unless . For example:
- Maximum 3-SAT cannot be approximated beyond a ratio.
- Maximum Clique cannot be approximated within for any .
- Set Cover cannot be approximated within .
These inapproximability results, derived from the theory of probabilistically checkable proofs, precisely delineate what is achievable in polynomial time.
Connection to Machine Learning
Approximate nearest neighbor search. Finding the exact nearest neighbor in high-dimensional spaces requires time exponential in the dimension (the curse of dimensionality). Approximation algorithms trade exactness for efficiency:
-
Locality-Sensitive Hashing (LSH) uses random hash functions that map nearby points to the same bucket with high probability. For a -approximate nearest neighbor, LSH achieves sublinear query time with appropriate hash families.
-
Hierarchical Navigable Small World (HNSW) graphs build a multi-layer proximity graph structure supporting approximate nearest neighbor queries in time empirically. While lacking worst-case guarantees as strong as LSH, HNSW achieves superior practical performance and is the backbone of modern vector databases (Faiss, Pinecone, Milvus).
These methods are essential to large-scale ML systems: retrieval-augmented generation, recommendation engines, and embedding-based search all depend on approximate nearest neighbor algorithms processing billions of vectors efficiently.