Sub topic 5
Greedy Set Cover and the ln n Bound
This chapter assumes you know the approximation ratio and the strategy of bounding the optimum from the previous chapters. It also uses Python sets and the harmonic series H_n = 1 + 1/2 + … + 1/n, which grows like ln n.
The Problem
In set cover you get a universe U of n elements and a family of subsets S1, …, Sm. You must choose the fewest subsets whose union is U. Vertex cover is a special case in which each edge is an element and each vertex is the set of edges touching it. General set cover is harder to approximate, and no constant-factor guarantee is possible for it.
The Greedy Rule
The greedy rule is to repeatedly pick 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]Each iteration scans all m subsets, and the loop runs at most min(m, n) times. The running time is therefore polynomial.
Proving the H_n Guarantee
The proof spreads the cost of each chosen set evenly over the elements it newly covers. If a set covers t new elements, each of those elements gets a price of 1/t. The total price over all elements equals the number of sets greedy picks.
Now bound each price. Let OPT be the optimal number of sets, and suppose k elements are still uncovered. The OPT optimal sets cover those k elements, so at least one of them covers at least k/OPT of them. Greedy picks a set at least that good, so every element it covers in this step costs at most OPT/k.
Order the elements by when they get covered. The j-th element covered has at most n − j + 1 elements still uncovered just before its step, so its price is at most OPT/(n − j + 1). Summing over all elements gives:
greedy ≤ OPT · (1/n + 1/(n−1) + … + 1) = H_n · OPT ≤ (ln n + 1) · OPT.
The lower bound on the optimum in this proof is local. In each step, the optimum's average coverage of the remaining elements limits how bad greedy's choice can be.
How Good Is This?
| Fact | Statement |
|---|---|
| Greedy upper bound | H_n ≈ ln n + 1 |
| Greedy on tight instances | ratio about log₂ n / 2, so the bound is right up to a constant factor |
| Hardness (Dinur–Steurer 2014) | no (1 − ε) ln n approximation unless P = NP |
Greedy is essentially the best possible polynomial-time algorithm for set cover.
Tight Example Sketch
Take two disjoint "rows" R1 and R2, which together are an optimal cover with 2 sets. Add "column" sets C1, C2, …, C_k of sizes 2, 4, 8, …, 2^k. Each column takes half its elements from each row. At every step, the largest remaining column covers more uncovered elements than either row, so greedy chooses all k columns. Here n = 2^(k+1) − 2, so greedy uses about log₂ n sets while the optimum uses 2.
Exercise
A set cover instance has a universe of 6 elements, and every subset has at most 3 elements. Greedy returns 7 sets. What is the smallest optimum consistent with the guarantee?
Show answer
Since subsets have at most 3 elements, the bound is H_3 = 1 + 1/2 + 1/3 = 11/6. So 7 ≤ (11/6)·OPT, which gives OPT ≥ 42/11 ≈ 3.82, so OPT ≥ 4. (The bound is loose here: with 6 elements every set covers at least one new element, so greedy picks at most 6 sets, and an output of 7 cannot actually occur.)
Exercise
Why does the proof use "at most n − j + 1 uncovered elements" for the j-th element covered, instead of exactly that number?
Show answer
Greedy covers several elements in one step, and they all share the same price. Just before that step, the number of uncovered elements is at least n − j + 1, so the price of the j-th element is at most OPT/(n − j + 1). Writing "at most" keeps the inequality correct for every element in a batch.