Greedy Coin-change Algorithm

Greedy selection-criteria: return largest coin that is less than or equal to the remaining change

Problem: Making 29-cents change with coins {1, 5, 10, 25, 50}

A 5-coin solution

Does this greedy algorithm always give the fewest number of coins?

Problem with Greedy Approach

Does not give the fewest coins for all coin sets.

Problem: Making 29-cents change with coins {1, 5, 10, 12, 25, 50}

This 5-coin solution is NOT optimal!

What solution would require the fewest coins?

Decrease-and-Conquer

Idea: Solve problem by:

Consider the coin-change problem: Given a set of coin types and an amount of change to be returned, determine the fewest number of coins for this amount of change.

What determines the size of the problem?

How could we divide the coin-change problem for 29-cents into smaller problems?

If we knew the solution to these smaller problems, how would be able to solve the original problem?

Decrease-and-Conquer Coin-change Solution

After we give back the first coin, then we have a smaller amount of change.

If we knew the fewest number of coins needed for each possible smaller problem, then how could determine the fewest number of coins needed for the original problem?

We can write a recursive relationship for the fewest number of coins as:

Problem with Divide-and-Conquer Solution

A lot of redundant calculations!!!

For coins of {1, 5, 10, 12, 25, 50}, typical timings:

Change Amount Run-Time (seconds)
50 1
55 5
60 26
65 126
70 613

Exponential growth in run-time!