Question: Design a greedy algorithm for making change after someone buys some candy costing x cents and the customer gives the clerk $1. Your algorithm should
Design a greedy algorithm for making change after someone buys some candy costing x cents and the customer gives the clerk $1. Your algorithm should try to minimize the number of coins returned.
a. Show that your greedy algorithm returns the minimum number of coins if the coins have denominations $0.25, $0.10, $0.05, and $0.01.
b. Give a set of denominations for which your algorithm may not return the minimum number of coins. Include an example where your algorithm fails.
Step by Step Solution
3.51 Rating (168 Votes )
There are 3 Steps involved in it
a Show that your greedy algorithm returns the minimum number of coins if the coins have denomination... View full answer
Get step-by-step solutions from verified subject matter experts
