Sub topic 2
Greedy Set Cover and the ln n Bound
This chapter assumes you know what an approximation ratio is, how a guarantee is proved by bounding the optimum (OPT), and what minimum spanning trees and NP-completeness reductions are.
Greedy Set Cover
The input is a universe U of n elements and a family of subsets of U. The goal is to pick the fewest subsets whose union is U. The greedy algorithm repeatedly picks the subset that covers the most elements that are still uncovered.
def greedy_set_cover(universe, subsets):
uncovered = set(universe)
chosen = []
while uncovered:
best = max(range(len(subsets)), key=lambda i: len(subsets[i] & uncovered))
if not subsets[best] & uncovered:
raise ValueError("universe cannot be covered by the given subsets")
chosen.append(best)
uncovered -= subsets[best]
return chosen
U = {1, 2, 3, 4, 5}
S = [{1, 2, 3}, {2, 4}, {3, 4}, {4, 5}]
print(greedy_set_cover(U, S)) # [0, 3]Why ln n. Suppose k elements are still uncovered. OPT's subsets cover them, so one of those subsets covers at least k/OPT of them. Greedy takes at least that many. Charge each newly covered element 1/(number newly covered). Then the element covered when k remained pays at most OPT/k. Adding these charges gives OPT·(1/n + … + 1) = H_n·OPT ≈ (ln n + 1)·OPT.
List Scheduling and LPT
The goal is to assign jobs to m identical machines so that the largest machine load (the makespan) is as small as possible. List scheduling puts each job on the machine with the least load. OPT is at least the average load, and OPT is at least the largest job. Look at the last job j placed on the machine that ends with the largest load. When j was placed, that machine was the least loaded, so its load then was at most the average. Adding p_j ≤ OPT gives a makespan of at most 2·OPT. A tighter version of this argument gives (2 − 1/m). LPT sorts jobs from largest to smallest first, which improves the bound to 4/3 − 1/(3m).
Metric TSP
In metric TSP, distances obey the triangle inequality. Deleting one edge from the optimal tour leaves a spanning tree, so MST ≤ OPT. Walking around the MST uses each edge twice, for a cost of 2·MST. Skipping vertices you have already visited never makes the walk longer, because of the triangle inequality. The result is a tour of cost at most 2·OPT. Christofides adds a minimum perfect matching on the odd-degree vertices instead of doubling the tree, which gives 1.5.
Why General TSP Cannot Be Approximated
Without the triangle inequality, no constant ratio ρ is achievable unless P = NP. Take a graph G and give its edges distance 1 and its non-edges distance ρn + 1. If G has a Hamiltonian cycle, the best tour costs n. Otherwise every tour costs more than ρn. A ρ-approximation would separate these two cases and so decide Hamiltonian cycle, which is NP-complete.
Local Search for Max-Cut
Start with any partition of the vertices into two sides. While some vertex has more neighbors on its own side than on the other side, move it to the other side. Each move adds at least one edge to the cut, so the process stops after at most |E| moves. When it stops, each vertex has at least half of its edges crossing the cut. Summing over all vertices shows the cut has at least |E|/2 ≥ OPT/2 edges.
Exercise
List scheduling places jobs 1, 1, 1, 1, then 4 on m = 2 machines. What makespan does it produce, what is OPT, and what does LPT produce?
Show answer
List scheduling gives loads 2 and 2, then the 4 makes one load 6. OPT is 4, using {4} and {1,1,1,1}. LPT places the 4 first, then the 1s on the other machine, which gives 4.