Greedy Algorithms8 sections · 316 units
Open in Course

Assign Cookies - Why Greedy Works

Proof sketch

Claim: matching smallest cookie to smallest satisfiable child is optimal. Proof: suppose there is a better solution where cookie jj goes to child ii' instead of ii, where i<ii < i' (child ii has smaller greed). Since i>ii' > i, greed[ii'] >= greed[ii]. Cookie jj could have satisfied child ii too. Swapping gives at least as many satisfied children.

By exchange argument, the greedy solution is optimal. This exchange proof works because swapping to a smaller cookie never hurts. The core idea: if a larger cookie works, the smaller one works too.