To make $6.39, you can choose:
- $5 bill
- $1 bill to make $6.
- 25¢ coin, to make $6.25
- 10¢ coin, to make $6.35
- Four 1¢ coins, to make $6.39.
However it doesn't work if the currency has coins with weights of 1,7, and 10. My question is, why does the greedy algorithm work [efficiently] only for a few weights? What are the conditions to be satisfied for the given set of weights to satisfy the greedy algorithm and be optimal at the same time?