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 13 with coins of 9, 6 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, 9, 1, 1, 1, 1.
  • That is the fewest, 6, 6, 1.
  • That is the amount.

new numbersthe test page's numbers

question 2

How many coins does greedy pay for 10 with coins of 6, 5 and 1?

the answer, and why

the answer is A

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

if you chose another

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

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 8 times on 11, 5, 1; 15, the most of the four.

if you chose another

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

new numbersthe test page's numbers