0

In change-making problem with following Greedy algorithms, addresses the following question: how can a given amount of money be made with the least number of coins?

Algorithm: using most valuable coins, if it possible. Suppose we have infinite numbers of each coins set.

my professor, wrote the (4) is not produce the optimal solution, anyone could say why? (or why other is not counterexample? )

1- {1,2,5}

2- {1,4,7}

3-{1,5,10}

4-{1,7,10}

1 Answers1

2

Applying a greedy strategy with coins from set #4 will not produce an optimal result in a situation when you need to represent 14:

  • Greedy strategy will take 10 as soon as it can, finishing off with four pennies, for a total of five coins
  • An optimal strategy would be to take two sevens, for a total of two coins.

It is easy to see that if there exists a coin C such that the value k*C can be composed with at least k+1 coins if you take any of the coins of higher denomination, then the greedy algorithm is not going to succeed.

In your last set C=7, k=2, kC=14. If you take 10 to make 14, you need five coins, which is greater than k.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • Would you please add a bit more detail ? and about other options? –  Feb 28 '15 at 19:19
  • would you please learn it me ? –  Feb 28 '15 at 19:27
  • How do u reach to 14? –  Feb 28 '15 at 19:44
  • @AliMovagher One needs to try numbers 1 up to `high_coin + second_highest_coin - 1`, in your case that's 1 through 16 (find a proof [here](http://people.cis.ksu.edu/~sathish/coinset.pdf)). I tried them manually. Your other three sets are optimal. – Sergey Kalinichenko Feb 28 '15 at 20:25
  • i know waste your valuable time, but how you check all of them :) i couldn't understand :) number of state is infinite :) –  Feb 28 '15 at 20:28
  • i read the PDF, but i couldn't understand, would you please add it to your answer with simple example? thanks anyway. –  Feb 28 '15 at 20:30
  • 1
    @AliMovagher It's not infinite - there is a very small number of ways to make change for values 1 through 16 with coins 1, 7, and 10. For 1 through 6 there's only one way, for 7, 8, and 9 there are two, for 10, 11, 12, and 13 there are three, and for 14, 15, and 16 there are four ways. You can easily enumerate them all, and see that the greedy approach would not find optimal solutions for 14, 15, 16, and 17. – Sergey Kalinichenko Feb 28 '15 at 21:33