Skip to content

Greedy change-making

planning ahead

Level 2 of 3

Also called Biggest coin first and The cashier's algorithm.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from greedy change-making's own run on the numbers shown.

choose one

question 1

How many comparisons does greedy make paying 14 with coins of 10, 7 and 1?

the answer, and why

the answer is D

5 coins taken and 3 kinds: each coin that fits is one comparison, and each kind is one more when it no longer fits.

if you chose another

  • That is the coins greedy pays, 10, 1, 1, 1, 1.
  • That is the fewest, 7, 7.
  • That is the amount.

new numbersthe test page's numbers

question 2

How many coins does greedy pay for 8 with coins of 5, 4 and 1?

the answer, and why

the answer is B

Greedy takes the biggest coin that fits each time: 5, 1, 1, 1, 4 coins.

if you chose another

  • That is the fewest, 4, 4, which greedy misses.
  • That pays it all in 1s.
  • No 1 of these coins make 8.

new numbersthe test page's numbers

question 3

Which coins and amount make greedy compare the most times? Each is written as the coins, then the amount.

the answer, and why

the answer is D

Greedy compares 9 times on 10, 7, 1; 15, the most of the four.

if you chose another

  • On those coins it compares 7 times, fewer than 9.
  • On those coins it compares 8 times, fewer than 9.
  • On those coins it compares 7 times, fewer than 9.

new numbersthe test page's numbers