02

Approximation Algorithms

Chapter 2 • Advanced

150 min

Approximation Algorithms

Approximation Ratio

Algorithm is α-approximate if:

OPT ≤ ALG ≤ α · OPT (minimization)

OPT/α ≤ ALG ≤ OPT (maximization)

Vertex Cover Approximation

2-Approximation

python.js
def vertex_cover_approx(graph):
    """2-approximation for Vertex Cover"""
    cover = set()
    edges = list(graph.edges())
    
    while edges:
        u, v = edges[0]
        cover.add(u)
        cover.add(v)
        # Remove all edges incident to u or v
        edges = [(x, y) for x, y in edges if x not in {u, v} and y not in {u, v}]
    
    return cover

Set Cover Approximation

Greedy Algorithm

python.js
def set_cover_approx(universe, sets):
    """Greedy approximation for Set Cover"""
    covered = set()
    cover = []
    
    while covered < universe:
        # Select set covering most uncovered elements
        best_set = max(sets, key=lambda s: len(s - covered))
        cover.append(best_set)
        covered |= best_set
    
    return cover

Practice Problems

  1. Vertex cover approximation
  2. Set cover approximation
  3. TSP approximation
  4. MAX-CUT approximation