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 10 with coins of 7, 5 and 1?

the answer, and why

the answer is B

4 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, 7, 1, 1, 1.
  • That is the fewest, 5, 5.
  • That is the amount.

new numbersthe test page's numbers

question 2

How many coins does greedy pay for 15 with coins of 12, 7 and 1?

the answer, and why

the answer is D

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

if you chose another

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

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 B

Greedy compares 8 times on 5, 4, 1; 13, the most of the four.

if you chose another

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

new numbersthe test page's numbers