Greedy-choice property
When picking the best option at each moment always leads to the best overall solution. If it holds, a greedy algorithm gives the optimum.
Example
With coins of 1, 5, 10, 20, 50 and 100, always taking the largest gives the minimum; with 1, 20 and 50, for 60 it fails: 11 coins instead of 3.
Test yourself: Greedy-choice property
Greedy algorithms
With coins [1, 20, 50] and amount 60, the greedy uses 11 coins, but the optimum uses ___.
20 + 20 + 20 = 60. The greedy takes 50 first and has to fill in with ten 1s.
Greedy algorithms
The greedy-choice property is easy to state but hard to ___.
For coins, even checking it takes an O(n³) algorithm: with 10 coin types, about 1,000 operations.
Fractional knapsack
The fractional knapsack proof is by ___.
It assumes the optimum does not use x and shows swapping 1 kg for x improves it: with x at 6 per kilo and another at 3, it rises by 3.
0/3
â–¶ Play