Algorithms

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 ___.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.