Learn
Lesson · Intractability and Approximation · Guarantees, and the lower bound they rest on

Charging Every Element

Greedy set cover takes the set covering the most uncovered elements. Its guarantee is not a constant: it is the harmonic number of the universe. The argument prices every element at the moment it is covered, shows the prices add to the answer exactly, and then bounds each price separately. On the loaded family greedy takes 3 sets where 2 suffice, the prices add to 3, and H over seven elements is 363/140.

a set covering k new elements charges each of them 1/k the charges add to the number of sets taken — exactly, every time seven elements, three sets: greedy 3, optimum 2 from 8 subfamilies, ratio 3/2 charges 1/4 · 4 + 1/2 · 2 + 1 · 1 = 3 H over 7 = 363/140 ≈ 2.593 the bound is H × optimum = 363/70 ≈ 5.186
Seven prices that add to three, and a bound that grows with the universe

Core ideas

What this lesson establishes

The first idea is the accounting trick that makes the analysis possible. The second is why the bound is a harmonic number rather than a constant. The third is what a logarithmic guarantee is worth in practice, which is more than it sounds.

1

Pricing turns one number into many

The answer is a count of sets, which is hard to bound directly. So hand each set's cost of 1 out to the elements it newly covered, equally: a set covering k new elements charges each of them 1/k. Every set gives away its whole cost and every element is charged exactly once, so the charges add to the number of sets taken. Now bounding the answer means bounding a sum of small quantities, and each can be bounded separately — which is the move that makes the proof work.

2

The bound is a harmonic number because the prices rise

When r elements are still uncovered, some set in an optimal cover of size OPT holds at least r / OPT of them, and greedy takes a set covering at least as many. So the element covered when r remain pays at most OPT / r. Adding over r = n down to 1 gives OPT · (1/n + ... + 1/1) = OPT · H_n. The prices rise as the cover fills up, and the last element can pay as much as OPT on its own.

3

A logarithm is not a constant, and it is not nothing

H_n grows without bound, so unlike vertex cover's factor of 2 this guarantee gets worse on larger instances — H over seven elements is about 2.59, over a thousand about 7.49. It is also essentially the best possible: no polynomial algorithm can do asymptotically better unless P = NP, a result quoted here and proved nowhere in this library. So the growing bound is a property of the problem and not a weakness of the analysis.

The material

The rule, the charging identity, the harmonic bound, and the family greedy gets wrong

The greedy rule, the pricing, the proof that the prices add to the answer, the bound on each price, and what the lab measured on a family designed to trip it.

Definition · Set cover, and the greedy rule

Given a family of sets whose union is a universe, find as few of them as possible whose union is still the whole universe. The greedy rule repeatedly takes a set covering the largest number of elements not yet covered, stopping when everything is covered.

Theorem · The charges add to the answer

If each set taken by greedy charges 1/k to each of the k elements it newly covers, then the sum of all charges equals the number of sets greedy took.

A

s

e

t

c

o

v

e

r

i

n

g

`

k

`

n

e

w

e

l

e

m

e

n

t

s

d

i

s

t

r

i

b

u

t

e

s

`

k

`

c

h

a

r

g

e

s

o

f

`

1

/

k

`

,

w

h

i

c

h

i

s

1

i

n

t

o

t

a

l

,

s

o

e

a

c

h

s

e

t

h

a

n

d

s

o

u

t

e

x

a

c

t

l

y

i

t

s

o

w

n

c

o

s

t

.

E

v

e

r

y

e

l

e

m

e

n

t

i

s

n

e

w

l

y

c

o

v

e

r

e

d

e

x

a

c

t

l

y

o

n

c

e

,

b

y

t

h

e

s

e

t

t

h

a

t

f

i

r

s

t

c

o

v

e

r

s

i

t

,

s

o

n

o

e

l

e

m

e

n

t

i

s

c

h

a

r

g

e

d

t

w

i

c

e

a

n

d

n

o

n

e

i

s

m

i

s

s

e

d

&

m

d

a

s

h

;

g

r

e

e

d

y

s

t

o

p

s

o

n

l

y

w

h

e

n

t

h

e

u

n

i

v

e

r

s

e

i

s

c

o

v

e

r

e

d

.

S

u

m

m

i

n

g

o

v

e

r

s

e

t

s

g

i

v

e

s

t

h

e

c

o

u

n

t

;

s

u

m

m

i

n

g

o

v

e

r

e

l

e

m

e

n

t

s

g

i

v

e

s

t

h

e

s

a

m

e

n

u

m

b

e

r

a

d

i

f

f

e

r

e

n

t

w

a

y

,

w

h

i

c

h

i

s

t

h

e

i

d

e

n

t

i

t

y

.

□

Theorem · Greedy set cover is within H_n of the optimum

Greedy returns a cover of size at most H_n · OPT, where n is the size of the universe, OPT is the size of a smallest cover and H_n = 1 + 1/2 + ... + 1/n.

Consider the moment an element is covered, with r elements uncovered including it. An optimal cover of size OPT covers all r, so one of its sets covers at least r / OPT of them; greedy takes a set covering at least that many new elements, so the charge is at most OPT / r.

The elements are covered in some order; the first is charged at most OPT / n, the next at most OPT / (n - 1), and so on down to at most OPT / 1 for the last. Adding, the total charge is at most OPT · H_n. By the identity the total charge is the size of greedy's cover, which gives the bound.

□

What the lab measured

The loaded family is {3,4,5,6}, {1,2,3}, {4,5,6,7} over the universe 1 to 7. Greedy takes the four-element set first, then needs two more; the optimum is 2, found by an exhaustive search over the 8 subfamilies, and it is the second and third sets together. The panel reports a realised ratio of 3/2, H over 7 as 363/140, the bound H × OPT as 363/70, the answer inside the bound, and the charges adding to the answer exactly.

The charges are 1/4 to each of the four elements the first set covered, 1/2 to each of the two the second set newly covered, and 1 to the single element the third set brought in. That is 4 × 1/4 + 2 × 1/2 + 1 = 3, which is the number of sets, and the panel checks the sum rather than showing the prices and moving on.

Example · The allowance each element was entitled to

With OPT = 2 and seven elements, the allowances OPT / r for r from 7 down to 1 are 2/7, 1/3, 2/5, 1/2, 2/3, 1, 2, adding to 2 · H_7 = 363/70. The realised charges are 1/4, 1/4, 1/4, 1/4, 1/2, 1/2, 1, and each is at or below its own allowance — the tightest being the first, 1/4 against 2/7. The bar chart draws each charge against the most the analysis allows it.

Why greedy loses here, and why it usually does not

The family is built to trip the rule. The four-element set is the largest, so greedy takes it first, and afterwards neither of the two sets that together cover everything is whole any more: one has two new elements and the other one. A rule that had looked ahead would have taken those two and finished. This is the same shape as the greedy failure the dynamic programming course opened on — a first choice that is locally best and globally wrong.

Most families are not like this. Switch to the disjoint partition and the ratio is 1 because every cover is the whole family; switch to the one big set with singletons under it and greedy takes the big set and stops, which is the optimum. The panel's default is the interesting case precisely because it is not the common one, and reading 3/2 as typical would be as wrong as reading 1 as a guarantee.

One number here is not a measurement: H_n and the bound H_n · OPT are the proved guarantee evaluated at this instance's numbers. 3/2 was counted. 363/70 was derived. They sit in the same panel and the gap between them — 1.5 against about 5.19 — is the usual state of an approximation guarantee: comfortable, and not evidence that the bound could be improved.

Interactive

Greedy set cover: every element pays, and the prices add up

A set covering k new elements charges each of them 1/k — the charges add to the answer, and each one has its own allowance

Greedy set cover: every element pays, and the prices add upa set that covers k new elements charges each of them 1/k, so the charges are the answer
the charge an element paidthe most it was allowed to paythe optimumthe bound, H times the optimum

Method

Running the charging argument on a cover you have built

The accounting is arithmetic. The discipline is checking that it balances before believing the bound.

1

Record how many NEW elements each chosen set covered

Not its size — its fresh count. A set covering four elements of which two were already covered charges 1/2, not 1/4, and getting this wrong makes the identity fail in a way that is easy to see and easy to overlook.

2

Add the charges and require the sum to be the number of sets

Exactly, as a fraction, not approximately. The identity is the hinge of the argument: if the sum is not the answer then the quantity being bounded is not the answer either. The panel prints the verdict as a separate row.

3

Bound each charge by OPT / r at the moment it was paid

r is the number of elements still uncovered when that element was covered, counting it. This is where the optimum enters the proof — once, as a bound on a set size in an optimal cover, and never as something the algorithm computes.

4

Add the allowances and recognise the harmonic number

OPT/n + OPT/(n-1) + ... + OPT/1 is OPT · H_n. Keep it exact: H_7 is 363/140, and a decimal here would hide that the bound is a sum of unit fractions, which is the whole reason it is logarithmic.

5

Report the realised ratio, the bound and the universe size together

The bound depends on n, so quoting a logarithmic guarantee without saying over what is quoting a function without its argument. The panel prints the universe size in the same row as the sets.

Charges, harmonics and what greedy is guaranteed

Score 0 / 0

Seven elements, three greedy choices, and the prices that add to three

The family is {3,4,5,6}; {1,2,3}; {4,5,6,7} over the universe 1 to 7. The optimum is the second and third sets. Greedy takes the largest first.

step set taken new elements charge each 1 {3,4,5,6} 3, 4, 5, 6 1/4 2 {1,2,3} 1, 2 1/2 3 {4,5,6,7} 7 1 element 3 4 5 6 1 2 7 charge 1/4 1/4 1/4 1/4 1/2 1/2 1 total 3 allowed 2/7 1/3 2/5 1/2 2/3 1 2 total 363/70 greedy 3 sets optimum 2, from 8 subfamilies ratio 3/2 H over 7 elements 363/140 ≈ 2.593 the bound H × optimum = 363/70 ≈ 5.186 3 ≤ 363/70 the charges add to the answer 3 = 3

The optimum is {1,2,3} together with {4,5,6,7}, and greedy takes both of them — just not first. Its mistake costs exactly one set, and the whole of the trap is that the largest set overlaps both members of the optimal cover. Remove the first set from the family and greedy is optimal.

The charge on element 7 is the most anything pays here, and it pays 1 because it was the last element covered and the set that covered it brought in nothing else. That is the general pattern: prices rise as the cover fills, and the bound is a sum of rising prices, which is what makes it harmonic rather than constant.

For a faded rehearsal, load the same trap one size up — ten elements, five sets — and predict the charges before running it. The supplied first move: greedy takes the six-element set first, charging 1/6 to each. Say how many more sets it needs, what those charges are, and check that they add to the number of sets; then compare the ratio with this instance's 3/2 and notice it has not changed while H has.

Common mistakes

1
Charging one over the set's sizeThe denominator is the number of elements the set covers that were not covered before. Using the size makes the charges add to less than the answer, and the identity the proof rests on quietly fails while every individual number still looks plausible.
2
Quoting a logarithmic guarantee without the universeH_n is a function of the number of elements, so “greedy is within a logarithmic factor” needs to say a logarithmic factor of what. Over seven elements the bound is about 2.59 and over a thousand about 7.49, and those are very different promises.
3
Reading 3/2 as what greedy usually doesThe loaded family was constructed to make greedy lose a set. Three of the panel's five families give a ratio of 1. The realised ratio is a fact about the family in the box, and the only statement covering all of them is the bound.

Check your understanding

✓
Finish when you can run the charging argument on a cover of your own and check that it balances.

You should be able to apply the greedy rule, record fresh counts rather than set sizes, price each element, verify the prices add to the number of sets exactly, bound each price by OPT over the number of elements then uncovered, and add the allowances to a harmonic number kept exact.

Note: Every guarantee so far has been fixed by the algorithm. “Accuracy by the Epsilon” is the last strategy and it inverts that: the reader names the accuracy, and the price is paid in the size of a table.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.