That is the smallest number of coins that will equal 63 cents (given that we don’t allow fifty-cent pieces). It has been proven that an optimal solution for coin changing can always be found using the current American denominations of coins. However, if we introduce some other denomination to the mix, the greedy algorithm doesn’t produce an optimal solution. Write a program that uses a greedy algorithm to make change (this code assumes change of less than one dollar).
The classic example of following a greedy
follows a greedy algorithm, he or she gives you two quarters, a dime, and three pennies. That is the smallest number of coins that will equal 63 cents (given that we don’t allow fifty-cent pieces). It has been proven that an optimal solution for coin changing can always be found using the current American denominations of coins. However, if we introduce some other denomination to the mix, the greedy algorithm doesn’t produce an optimal solution.
Write a
Step by step
Solved in 2 steps with 1 images