Simple Algorithm
Algorithms & Data Structures · Optimized · 24 min

Approximation Algorithms

Provably near-optimal answers when optimal is out of reach.

Finding a smallest vertex cover is NP-hard, yet a ten-line loop always returns a cover at most twice as large as the smallest one, without ever learning how large the smallest one is. Every approximation algorithm runs on the same trick: compare your answer with a bound on the optimum that you can compute.

What you’ll learn

  • Define the approximation ratio for minimization and maximization problems, and prove a ratio by comparing the answer with a computable lower bound on the optimum.
  • Prove that a maximal matching gives a 2-approximation for vertex cover, and that greedy set cover is within Hn≤ln⁡n+1H_n \le \ln n + 1 of optimal.
  • Prove the 2-approximation for metric TSP by tree doubling, state Christofides' 3/23/2, and show that TSP without the triangle inequality has no constant-factor approximation unless P = NP.
  • Analyze greedy load balancing (2−1/m2 - 1/m) and LPT, and place problems on the map of FPTAS, PTAS, APX-hard and inapproximable.
  • Recognize when a problem calls for an approximation algorithm, a heuristic, or an exact algorithm after all.

Ratios and the lower-bound trick

Many optimization problems in this course have fast exact algorithms: shortest paths, minimum spanning trees, maximum flows. For NP-hard ones such as vertex cover, set cover and the traveling salesman problem, no polynomial-time algorithm is known, and the lesson P, NP & NP-Completeness explains why none is expected. Brute force still works, but trying all 2n2^n subsets of vertices is hopeless beyond a few dozen vertices.

An approximation algorithm gives up exactness, not speed and not rigor: it runs in polynomial time and comes with a proof that its answer is never far from optimal.

The catch: you cannot compute OPT\mathrm{OPT}, so how can you prove anything about it? Find a quantity LB(I)\mathrm{LB}(I) that you can compute in polynomial time and that never exceeds the optimum, then show that your answer is at most α\alpha times that bound:

ALG(I) ≤ α⋅LB(I) ≤ α⋅OPT(I)\mathrm{ALG}(I)\ \le\ \alpha\cdot \mathrm{LB}(I)\ \le\ \alpha\cdot \mathrm{OPT}(I)
Every proof in this lesson has this shape; only the lower bound changes.
ProblemLower bound on OPTWhy it is a lower boundRatio it yields
Vertex coverthe size of a maximal matching MMa cover needs a different endpoint for each edge of MM2
Metric TSPthe weight of a minimum spanning treedeleting one edge of a tour leaves a spanning tree2 (tree doubling), 3/23/2 (Christofides)
Load balancing on mm machinesmax⁡(max⁡jtj, 1m∑jtj)\max\big(\max_j t_j,\ \tfrac1m\sum_j t_j\big)some machine runs the longest job, and some machine gets at least the average load2−1/m2 - 1/m
Weighted covering problemsthe optimum of a linear-programming relaxationrelaxing the constraints can only lower a minimum2 for vertex cover, O(log⁡n)O(\log n) for set cover
The last row is the subject of the Optimal lesson LP Relaxation & Rounding.
Check your understanding

Your algorithm returns a vertex cover of 90 vertices on a graph in which you have also found a matching of 50 edges. What do you know about the size OPT\mathrm{OPT} of a minimum cover?

  1. 45≤OPT≤9045 \le \mathrm{OPT} \le 90
  2. 50≤OPT≤9050 \le \mathrm{OPT} \le 90
  3. OPT=50\mathrm{OPT} = 50
  4. OPT≤50\mathrm{OPT} \le 50
Show the answer

B. 50≤OPT≤9050 \le \mathrm{OPT} \le 90

Each of the 50 matching edges needs its own endpoint in every cover, so OPT≥50\mathrm{OPT} \ge 50; your answer is a cover, so OPT≤90\mathrm{OPT} \le 90. On this instance your cover is within 90/50=1.890/50 = 1.8 of optimal.

Vertex cover: twice a maximal matching

A vertex cover of a graph G=(V,E)G = (V, E) is a set C⊆VC \subseteq V that touches every edge. Finding a smallest one is NP-hard, and brute force tries up to 2n2^n subsets. The approximation is almost embarrassingly simple: while some edge uvuv is uncovered, put both uu and vv into the cover.

python
def vertex_cover_2approx(edges):
    cover = set()
    for u, v in edges:                 # scan the edges once, in any order
        if u not in cover and v not in cover:
            cover.add(u)               # (u, v) joins the matching M:
            cover.add(v)               # take both of its endpoints
    return cover

path = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)]
print(sorted(vertex_cover_2approx(path)))   # [0, 1, 2, 3, 4, 5], while {1, 3, 5} suffices

One pass, O(n+m)O(n + m) time. The edges that trigger an insertion form a matching MM, since no two of them share an endpoint, and it is maximal: every other edge touches one of them, or it would have been taken.

DerivationProof
  1. ∀ uv∈E:u∈C  ∨  v∈C\forall\, uv \in E:\quad u \in C\ \ \lor\ \ v \in C

    CC is a cover. An edge is skipped only when one of its endpoints is already in CC, and every edge that is not skipped puts both endpoints in.

  2. OPT ≥ ∣M∣\mathrm{OPT}\ \ge\ \abs{M}

    Lower bound. The edges of MM share no endpoints, so every cover, an optimal one included, contains a different vertex for each of them:

  3. ∣C∣ = 2∣M∣ ≤ 2 OPT\abs{C}\ =\ 2\abs{M}\ \le\ 2\,\mathrm{OPT}

    Upper bound. The algorithm adds exactly two vertices per matching edge:

The analysis is tight: on nn disjoint edges, or on the complete bipartite graph Kn,nK_{n,n}, the algorithm takes all 2n2n vertices while nn suffice. Nobody knows a polynomial-time algorithm with ratio 2−ε2 - \varepsilon for any constant ε>0\varepsilon > 0, and the Optimal lesson Hardness of Approximation & the PCP Theorem explains why 2 may be the truth.

Check your understanding

Why does the algorithm take both endpoints of an uncovered edge instead of just one?

  1. Taking one endpoint could leave the edge uncovered
  2. Every cover must contain uu or vv, and you do not know which, so taking both pays at most twice what the optimum pays for that edge
  3. Taking both endpoints is faster than deciding between them
  4. It does not matter: taking one endpoint, chosen arbitrarily, also guarantees ratio 2
Show the answer

B. Every cover must contain uu or vv, and you do not know which, so taking both pays at most twice what the optimum pays for that edge

The charging argument needs each chosen pair to contain a vertex that the optimum also pays for, and disjoint pairs to be charged to different optimal vertices. With one arbitrary endpoint the guarantee breaks: on a star, always picking the leaf takes all n−1n - 1 leaves, while the center alone is a cover.

Greedy set cover and the ln n barrier

In set cover you are given a universe UU of nn elements and a family of subsets S1,…,SkS_1, \dots, S_k whose union is UU, and you want the fewest subsets whose union is still UU. It models choosing sensors that watch every room, tests that exercise every feature, or fire stations that reach every street. Vertex cover is the special case in which the elements are edges and each vertex is the set of edges it touches.

The natural greedy rule: repeatedly take the set that covers the most elements not yet covered.

python
def greedy_set_cover(universe, sets):
    uncovered, chosen = set(universe), []
    while uncovered:
        best = max(range(len(sets)), key=lambda i: len(sets[i] & uncovered))
        if not sets[best] & uncovered:
            return None                    # some element is in no set
        chosen.append(best)
        uncovered -= sets[best]
    return chosen

Each round scans all sets, and there are at most min⁡(n,k)\min(n, k) rounds. Keeping the sets in buckets by their number of uncovered elements brings the whole run down to O(∑i∣Si∣)O(\sum_i \abs{S_i}).

DerivationProof by charging
  1. ∣greedy∣ = ∑e∈Uprice⁡(e)\abs{\text{greedy}}\ =\ \sum_{e \in U} \operatorname{price}(e)

    Spread the cost. When greedy takes a set that covers cc new elements, charge each of them a price of 1/c1/c. The prices add up to the number of sets chosen:

  2. price⁡(ej) ≤ OPTn−j+1\operatorname{price}(e_j)\ \le\ \frac{\mathrm{OPT}}{n - j + 1}

    Price of one element. Number the elements e1,…,ene_1, \dots, e_n in the order greedy covers them. Just before the round that covers eje_j, at least n−j+1n - j + 1 elements are uncovered. The OPT\mathrm{OPT} sets of an optimal solution cover all of them, so one of those sets covers at least (n−j+1)/OPT(n - j + 1)/\mathrm{OPT} of them, and greedy's choice covers at least as many:

  3. ∣greedy∣ ≤ ∑j=1nOPTn−j+1 = Hn⋅OPT ≤ (ln⁡n+1) OPT\abs{\text{greedy}}\ \le\ \sum_{j=1}^{n}\frac{\mathrm{OPT}}{n-j+1}\ =\ H_n\cdot\mathrm{OPT}\ \le\ (\ln n + 1)\,\mathrm{OPT}

    Sum over all elements:

Greedy really can be about log⁡n\log n times worse. Split n=2k+1−2n = 2^{k+1} - 2 elements into blocks B1,…,BkB_1, \dots, B_k with ∣Bi∣=2i\abs{B_i} = 2^i, offer each block as a set, and add two sets T1T_1 and T2T_2 holding the first and second halves of every block. T1∪T2=UT_1 \cup T_2 = U, so OPT=2\mathrm{OPT} = 2. But BkB_k covers 2k2^k elements and each TT only 2k−12^k - 1, so greedy takes BkB_k first, then Bk−1B_{k-1} for the same reason, and so on: k≈log⁡2nk \approx \log_2 n sets. With k=4k = 4, greedy takes 4 sets to cover 30 elements that 2 sets cover.

Predict before you look

Greedy set cover runs on a universe of 1,000 elements, so its guarantee is the factor H1000H_{1000}. Estimate it, using Hn≈ln⁡n+0.5772H_n \approx \ln n + 0.5772.

Show the answer

7.49

ln⁡1000≈6.908\ln 1000 \approx 6.908, so H1000≈7.485H_{1000} \approx 7.485: greedy never uses more than about 7.5 times the optimal number of sets. The factor grows only logarithmically; for a million elements it is about 14.4.

Metric TSP: doubling a spanning tree

The traveling salesman problem (TSP) asks for the shortest tour that visits every city once and returns to the start. Here the distances matter. In metric TSP they are symmetric and obey the triangle inequality d(u,w)≤d(u,v)+d(v,w)d(u, w) \le d(u, v) + d(v, w), as straight-line and shortest road distances do: a detour never makes a trip shorter.

The lower bound is a minimum spanning tree TT. Delete any edge of an optimal tour and you are left with a path through all the cities, which is a spanning tree, so w(T)≤OPTw(T) \le \mathrm{OPT}.

DerivationTree doubling is a 2-approximation
  1. w(walk) = 2 w(T) ≤ 2 OPTw(\text{walk})\ =\ 2\,w(T)\ \le\ 2\,\mathrm{OPT}

    Walk around the tree. A depth-first walk from any city traverses each edge of TT twice, once down and once back, and ends where it started:

  2. d(u,w) ≤ d(u,v1)+d(v1,v2)+⋯+d(vj,w)d(u, w)\ \le\ d(u, v_1) + d(v_1, v_2) + \dots + d(v_j, w)

    Shortcut. The walk revisits cities. Skip every city already seen and jump straight to the next new one. By the triangle inequality, applied repeatedly, a jump from uu to ww costs no more than the stretch of walk u,v1,…,vj,wu, v_1, \dots, v_j, w that it replaces:

  3. w(tour) ≤ w(walk) ≤ 2 OPTw(\text{tour})\ \le\ w(\text{walk})\ \le\ 2\,\mathrm{OPT}

    Result. The shortcut walk visits the cities in depth-first preorder, each once: a tour.

Christofides' algorithm (1976; found independently by Serdyukov, 1978) repairs the tree more cheaply. What stops a tree from being walked as a closed trail that uses each edge once is its odd-degree vertices. Instead of doubling every edge, add a minimum-weight perfect matching on the odd-degree vertices only. That matching costs at most OPT/2\mathrm{OPT}/2, so the final tour costs at most 32 OPT\tfrac32\,\mathrm{OPT}. The full proof, and the 2021 improvement to 32−ε\tfrac32 - \varepsilon for some ε>10−36\varepsilon > 10^{-36}, are in the Optimal lesson Approximating the Traveling Salesman.

DerivationProof: a gap from Hamiltonian cycle
  1. d(u,v)={1if uv∈E(G),αn+1otherwise.d(u, v) = \begin{cases} 1 & \text{if } uv \in E(G), \\ \alpha n + 1 & \text{otherwise.} \end{cases}

    Take any graph GG on nn vertices, an instance of the NP-complete Hamiltonian cycle problem, and build a TSP instance on the same vertices:

  2. G Hamiltonian⇒OPT=n,G not Hamiltonian⇒OPT ≥ (n−1)+αn+1 > αnG \text{ Hamiltonian} \Rightarrow \mathrm{OPT} = n, \qquad G \text{ not Hamiltonian} \Rightarrow \mathrm{OPT}\ \ge\ (n - 1) + \alpha n + 1\ >\ \alpha n

    If GG has a Hamiltonian cycle, that cycle is a tour of length nn. If not, every tour uses at least one non-edge of GG:

  3. ALG≤αn  ⟺  G is Hamiltonian\mathrm{ALG} \le \alpha n \iff G \text{ is Hamiltonian}

    An α\alpha-approximation returns at most αn\alpha n in the first case and more than αn\alpha n in the second, so comparing its answer with αn\alpha n decides Hamiltonicity in polynomial time, and P = NP.

These distances violate the triangle inequality wildly: a non-edge costs far more than a two-step detour through a neighbor, and a detour is exactly what shortcutting refuses to pay for.

Check your understanding

Where exactly does the tree-doubling proof use the triangle inequality?

  1. In w(T)≤OPTw(T) \le \mathrm{OPT}, since deleting a tour edge gives a spanning tree
  2. In the doubled walk costing exactly 2 w(T)2\,w(T)
  3. In the shortcut step: jumping past cities already visited must not lengthen the walk
  4. Nowhere: the proof works for any distances
Show the answer

C. In the shortcut step: jumping past cities already visited must not lengthen the walk

A tour minus an edge is a spanning path for any non-negative distances, and the doubled walk costs 2 w(T)2\,w(T) in any graph. Only replacing a stretch of the walk by one direct jump needs d(u,w)≤d(u,v)+d(v,w)d(u, w) \le d(u, v) + d(v, w).

Load balancing, and the landscape of ratios

You have mm identical machines and nn jobs with processing times t1,…,tnt_1, \dots, t_n, and you want to minimize the makespan, the time at which the last machine finishes. The problem is NP-hard already for m=2m = 2, where it contains the partition problem. Graham's list scheduling (1966) places each job, in the given order, on the machine with the least load so far.

python
import heapq

def list_schedule(times, m):
    loads = [(0, i) for i in range(m)]          # (load, machine): a min-heap
    for t in times:
        load, i = heapq.heappop(loads)           # the least-loaded machine
        heapq.heappush(loads, (load + t, i))
    return max(load for load, _ in loads)        # the makespan

m = 4
print(list_schedule([1] * (m * (m - 1)) + [m], m))            # 7, while OPT = 4
print(list_schedule(sorted([3, 3, 2, 2, 2], reverse=True), 2))  # LPT: 7, while OPT = 6

O(nlog⁡m)O(n \log m) with a heap. In the first call, twelve unit jobs fill the four machines to load 3, and the long job lands on top: 3+4=73 + 4 = 7. The optimum puts the long job alone on one machine and four unit jobs on each of the others: makespan 4.

DerivationList scheduling is a (2 − 1/m)-approximation
  1. OPT ≥ max⁡jtj,OPT ≥ W/m\mathrm{OPT}\ \ge\ \max_j t_j, \qquad \mathrm{OPT}\ \ge\ W/m

    Two lower bounds. Some machine runs the longest job, and the total work W=∑jtjW = \sum_j t_j, spread over mm machines, leaves some machine with at least the average:

  2. m (Li−tj) ≤ W−tjm\,(L_i - t_j)\ \le\ W - t_j

    The last job. Let machine ii finish last, with load LiL_i, and let tjt_j be the last job placed on it. When jj was placed, machine ii had the smallest load, Li−tjL_i - t_j, so every machine had at least that much, and only jobs other than jj had been placed:

  3. Li ≤ W−tjm+tj = Wm+(1−1m)tj ≤ (2−1m)OPTL_i\ \le\ \frac{W - t_j}{m} + t_j\ =\ \frac{W}{m} + \Big(1 - \frac1m\Big)t_j\ \le\ \Big(2 - \frac1m\Big)\mathrm{OPT}

    Combine the two:

The first example in the code meets this bound exactly, 7=(2−14)⋅47 = (2 - \tfrac14)\cdot 4: the long job arrives last. Sorting the jobs longest first, the LPT rule, fixes exactly that. Graham (1969) proved that LPT's makespan is at most (43−13m)OPT\big(\tfrac43 - \tfrac1{3m}\big)\mathrm{OPT}, again tight: the second example gives 7=(43−16)⋅67 = \big(\tfrac43 - \tfrac16\big)\cdot 6.

ProblemBest ratio knownKnown limit (unless P = NP)
0/1 knapsackFPTASonly exactness is NP-hard
Makespan on identical machinesPTAS (Hochbaum & Shmoys, 1987)no FPTAS: strongly NP-hard
Euclidean TSP in the planePTAS (Arora, 1998; Mitchell, 1999)no FPTAS: strongly NP-hard
Vertex cover22−ε\sqrt2 - \varepsilon (Khot, Minzer & Safra, 2018); 2−ε2 - \varepsilon if the Unique Games Conjecture holds
Metric TSP32−ε\tfrac32 - \varepsilon, ε>10−36\varepsilon > 10^{-36} (Karlin, Klein & Oveis Gharan, 2021)123122\tfrac{123}{122} (Karpinski, Lampis & Schmied, 2015)
Set coverHn≤ln⁡n+1H_n \le \ln n + 1 (greedy)(1−ε)ln⁡n(1 - \varepsilon)\ln n (Dinur & Steurer, 2014)
Maximum clique, maximum independent setlittle better than the trivial factor nnn1−εn^{1 - \varepsilon} (Håstad, 1999; Zuckerman, 2007)
TSP with arbitrary distancesnoneevery ratio (Sahni & Gonzalez, 1976)
The state of the art as of 2025. An algorithm beating a limit in the last column would prove P = NP, or, for the vertex-cover entry under Unique Games, refute that conjecture.
Check your understanding

An algorithm for a minimization problem returns a (1+ε)(1 + \varepsilon)-approximation in O(n2/ε)O(n^{2/\varepsilon}) time, for every ε>0\varepsilon > 0. What is it?

  1. An FPTAS
  2. A PTAS, but not an FPTAS
  3. Not a polynomial-time algorithm for any fixed ε\varepsilon
  4. Just a 2-approximation
Show the answer

B. A PTAS, but not an FPTAS

For each fixed ε\varepsilon the running time is a polynomial, n20n^{20} for ε=0.1\varepsilon = 0.1, so it is a PTAS. It is not an FPTAS, because 1/ε1/\varepsilon sits in the exponent instead of in a polynomial factor.

Recognizing it

Reach for an approximation algorithm when these signals appear together:

  • An NP-hard optimization core at a size exact search cannot touch: covering, packing, routing, scheduling or clustering with thousands of items. (With a few dozen items, exact methods from the lesson Coping with NP-Hardness may still work.)
  • An objective that tolerates slack: a schedule 5% longer or a network 10% more expensive is acceptable. A yes/no question is not approximable in this sense.
  • Metric structure: distances that obey the triangle inequality make TSP, facility location and clustering approximable within constants.
  • A need for a guarantee, not just a good answer on average. Local search and other heuristics often do better in practice but promise nothing, so a common recipe runs both and uses the approximation's lower bound to certify the heuristic's answer.
Problem, in briefKey ideaGuarantee and cost
Place the fewest guards at street corners so that every street is watchedvertex cover: both endpoints of a maximal matching (LP rounding when corners have prices)ratio 2, O(n+m)O(n + m)
Choose the fewest test cases that together exercise every featureset cover: greedy by the most features not yet exercisedratio HnH_n, O(∑i∣Si∣)O(\sum_i \abs{S_i}) with buckets
Route a van through 2,000 addresses on a road network and back to the depotmetric TSP: Christofides for the guarantee, then 2-opt moves, which only shorten the tourratio 3/23/2; typically within a few percent after polishing
Spread 10,000 render jobs over 64 identical servers to finish as early as possiblemakespan: LPT, longest job first onto the least-loaded serverratio 43−13m\tfrac43 - \tfrac1{3m}, O(nlog⁡n)O(n \log n)
In each row the guarantee comes from a lower bound: a matching, the uncovered-element count, a spanning tree plus a matching, and the larger of the average load and the longest job.

Common bugs.

  • Proving a ratio against something that is not a lower bound: the spanning tree of only some of the cities, or a set of edges that is not a matching.
  • Mixing conventions: for maximization, "ratio 2" means at least half the optimum; for minimization, at most twice it.
  • Shortcutting a walk when distances are asymmetric or break the triangle inequality: the 2 and 3/23/2 guarantees silently vanish.
  • Edge cases: no jobs (makespan 0), one city (a tour of length 0), two cities (twice their distance), an element that no set contains (no cover exists).
  • Trusting a worst-case ratio as a forecast: the matching algorithm is often beaten in practice by LP rounding plus a cleanup pass that drops redundant vertices.
Check your understanding

A logistics team must route one truck through 3,000 stops on a road network whose travel times obey the triangle inequality. They want a route provably at most 50% longer than optimal, computed within minutes. What should they use?

  1. Held–Karp dynamic programming, to get the exact optimum
  2. Nearest neighbor alone, since it is the fastest
  3. Tree doubling, since it is the only algorithm here with a guarantee
  4. Christofides' algorithm, then 2-opt moves that can only shorten the tour
Show the answer

D. Christofides' algorithm, then 2-opt moves that can only shorten the tour

Christofides guarantees at most 1.5 times the optimum on metric instances in polynomial time, and every 2-opt move shortens the tour, so the guarantee survives the polishing.

Key takeaways

  • An α\alpha-approximation runs in polynomial time and is within a factor α\alpha of optimal on every instance. Its proof compares the answer with a computable lower bound on OPT\mathrm{OPT}: a matching, a spanning tree, an average load or an LP optimum.
  • Both endpoints of a maximal matching form a vertex cover at most twice the minimum; greedy set cover is within Hn≤ln⁡n+1H_n \le \ln n + 1, and beating (1−ε)ln⁡n(1 - \varepsilon)\ln n is NP-hard.
  • For metric TSP, tree doubling gives 2 and Christofides 3/23/2; without the triangle inequality, no ratio at all is achievable unless P = NP.
  • List scheduling gives 2−1/m2 - 1/m for makespan and LPT 43−13m\tfrac43 - \tfrac1{3m}. Problems range from FPTAS (knapsack) and PTAS (Euclidean TSP) to APX-hard (vertex cover, metric TSP) and inapproximable (clique, general TSP).

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

The matching algorithm returns a vertex cover of 40 vertices. Which statement is guaranteed?

  1. The minimum cover has exactly 20 vertices
  2. The minimum cover has at least 20 and at most 40 vertices
  3. The minimum cover has at most 20 vertices
  4. The minimum cover has at least 40 vertices
Show the answer

B. The minimum cover has at least 20 and at most 40 vertices

The algorithm took 20 matching edges, and every cover needs a different vertex for each of them, so OPT≥20\mathrm{OPT} \ge 20. The returned set is itself a cover, so OPT≤40\mathrm{OPT} \le 40.

Question 2

Why is the weight of a minimum spanning tree a lower bound on the length of an optimal tour, for any non-negative distances?

  1. Every tour contains a minimum spanning tree
  2. Because of the triangle inequality
  3. Deleting one edge from an optimal tour leaves a spanning path, which is a spanning tree and so weighs at least as much as a minimum one
  4. A tour and a tree both visit every city exactly once
Show the answer

C. Deleting one edge from an optimal tour leaves a spanning path, which is a spanning tree and so weighs at least as much as a minimum one

An optimal tour minus any edge is a path through all the cities: one particular spanning tree. A minimum spanning tree weighs at most as much, so w(T)≤OPT−(deleted edge)≤OPTw(T) \le \mathrm{OPT} - (\text{deleted edge}) \le \mathrm{OPT}.

Question 3

A TSP instance has arbitrary positive distances, not necessarily obeying the triangle inequality. Assuming P ≠ NP, what can a polynomial-time algorithm guarantee?

  1. A factor 2, by tree doubling
  2. A factor 3/23/2, by Christofides' algorithm
  3. A factor O(log⁡n)O(\log n), by greedy
  4. No constant factor at all
Show the answer

D. No constant factor at all

Give the edges of a graph GG distance 1 and its non-edges distance αn+1\alpha n + 1. The optimal tour costs nn if GG has a Hamiltonian cycle and more than αn\alpha n otherwise, so an α\alpha-approximation would decide Hamiltonicity, an NP-complete problem.

Question 4

Greedy set cover is within Hn≈ln⁡nH_n \approx \ln n of optimal, and approximating set cover within (1−ε)ln⁡n(1 - \varepsilon)\ln n is NP-hard. What do the two results say together?

  1. Greedy finds an optimal cover on every instance
  2. Unless P = NP, no polynomial-time algorithm has a worst-case ratio substantially better than greedy's
  3. Greedy's analysis is loose by a factor of ln⁡n\ln n
  4. Set cover can be solved exactly in polynomial time when nn is small
Show the answer

B. Unless P = NP, no polynomial-time algorithm has a worst-case ratio substantially better than greedy's

The upper bound Hn=ln⁡n+O(1)H_n = \ln n + O(1) and the lower bound (1−ε)ln⁡n(1 - \varepsilon)\ln n meet up to lower-order terms, so greedy's worst-case guarantee is essentially the best possible for polynomial-time algorithms, assuming P ≠ NP.

Question 5

Assuming P ≠ NP, which of these problems has a fully polynomial-time approximation scheme (FPTAS)?

  1. 0/1 knapsack
  2. Bin packing
  3. Metric TSP
  4. Vertex cover
Show the answer

A. 0/1 knapsack

Knapsack is only weakly NP-hard: its dynamic program is pseudo-polynomial, and rounding the values gives a (1−ε)(1 - \varepsilon)-approximation in time polynomial in nn and 1/ε1/\varepsilon. The other three are strongly NP-hard or APX-hard, which rules out an FPTAS.

Go deeper

Further reading

  • D. P. Williamson & D. B. Shmoys, The Design of Approximation Algorithms (Cambridge University Press, 2011), chapters 1–3.
  • V. V. Vazirani, Approximation Algorithms (Springer, 2001).
  • J. Kleinberg & É. Tardos, Algorithm Design (Addison-Wesley, 2005), chapter 11.
  • T. H. Cormen, C. E. Leiserson, R. L. Rivest & C. Stein, Introduction to Algorithms, 4th ed. (MIT Press, 2022), chapter 35.