On this page
Set cover asks for the fewest bundles that cover a whole list. Repeatedly grabbing the bundle that covers the most uncovered items is provably good, and about as good as any fast method can be.
What is the set cover problem?
You are given a universe U of n elements and a family of subsets of U. A set cover is a choice of subsets whose union is all of U, and the goal is to use as few subsets as possible. Uriel Feige's 1998 paper in the Journal of the ACM states the problem this way and notes that it is NP-hard.
How does the greedy algorithm for set cover work?
Start with every element uncovered.
Pick the set that covers the most still-uncovered elements (break ties any way).
Mark those covered and repeat until nothing is left.
The key word is new: already-covered elements count for nothing.
A worked example: your revision list has chapters 1 to 8, and five mock papers cover them like this:
A = {1, 2, 3, 4, 5}
B = {1, 2, 6}
C = {3, 6, 7}
D = {4, 5, 8}
E = {2, 8}
Round 1: A covers 5, more than any other. Take A. Left: {6, 7, 8}.
Round 2: B adds 1 (chapter 6), C adds 2 (6 and 7), D adds 1 (8), E adds 1 (8). Take C. Left: {8}.
Round 3: D or E covers chapter 8. Greedy's answer is 3 papers.
Could 2 papers do it? Without A, two papers cover at most 6 chapters. With A, the partner must contain 6, 7 and 8, and none does. So 3 is optimal, and greedy found it.
Why is greedy within H_n ≈ ln n of optimal?
The bound was proved by David Johnson in 197480044-9) and by László Lovász, and Vašek Chvátal extended it in 1979 to sets with costs, showing the ratio between greedy and the optimum grows at most logarithmically in the size of the largest set.
Suppose the best cover uses OPT sets. When greedy picks a set covering k new elements, give each of them a price of 1/k. Each round adds exactly 1, so total price = number of greedy sets.
List the elements in the order greedy covers them. Just before the j-th is covered, at least n − j + 1 elements remain. The OPT sets cover all of them, so one of those sets contains at least (n − j + 1)/OPT of them. Greedy takes a set at least that good, so the j-th price is at most OPT/(n − j + 1).
Adding up: greedy ≤ OPT × (1/n + ... + 1/2 + 1) = OPT × H_n.
The harmonic number H_n is at most ln n + 1; it is the same sum behind the harmonic overhang of stacked books. If the largest set has d elements, a sharper version of the argument gives the factor H_d, the form Chvátal proved for sets with costs.
When does greedy do badly?
Take 14 elements in two rows of 7. The two rows are the best cover. Now add three column blocks: S1 is the first 4 columns (8 elements), S2 the next 2 (4 elements), S3 the last one (2 elements).
Greedy compares 8 with 7 and takes S1, then 4 with 3 and takes S2, then 2 with 1 and takes S3. Greedy uses 3 sets; the answer is 2.
Scale it up: with k blocks of 2^k, 2^(k−1), ..., 2 elements, n = 2^(k+1) − 2, greedy takes all k blocks and 2 rows still suffice. The ratio k/2 grows like (log₂ n)/2 ≈ 0.72 ln n, the same figure Feige's abstract quotes for the earlier hardness result of Lund and Yannakakis. Greedy colouring and Brooks' theorem show a similar pattern: a fast rule whose guarantee is not always the best possible.
Can any algorithm beat ln n for set cover?
Feige showed that (1 − o(1)) ln n is a threshold below which set cover cannot be approximated efficiently unless NP has slightly superpolynomial-time algorithms, closing the gap with greedy up to low-order terms.
Dana Moshkovitz's 2015 paper in Theory of Computing, together with a result of Irit Dinur and David Steurer, implies that approximating set cover within (1 − α) ln n is NP-hard for every fixed α > 0. So unless P = NP, greedy is essentially the best polynomial-time method, a trade-off also seen in the travelling salesman problem.
How should you practise set cover?
Rerun the mock-paper example with E = {6, 7, 8}: greedy takes A, then E, and stops at 2 papers.
Build the 30-element trap (k = 4) and check that greedy takes all four blocks.
Rewrite the pricing proof from memory, then try to sharpen it to H_d.
If harmonic sums or NP-hardness feel shaky, the Fermi Concept Library has every concept in mathematics and computing, each with its own lesson. The Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



