1.

Suppose you have coins of denominations 1,3 and 4. You use a greedy algorithm, in which you choose the largest denomination coin which is not greater than the remaining sum. For which of the following sums, will the algorithm produce an optimal answer?(a) 14(b) 10(c) 6(d) 100The question was asked in my homework.The query is from Coin Change Problem topic in chapter Dynamic Programming of Data Structures & Algorithms II

Answer»

Correct CHOICE is (d) 100

The best I can explain: Using the greedy ALGORITHM, three COINS {4,1,1} will be selected to make a sum of 6. But, the optimal ANSWER is two coins {3,3}. Similarly, four coins {4,4,1,1} will be selected to make a sum of 10. But, the optimal answer is three coins {4,3,3}. ALSO, five coins {4,4,4,1,1} will be selected to make a sum of 14. But, the optimal answer is four coins {4,4,3,3}. For a sum of 100, twenty-five coins {all 4’s} will be selected and the optimal answer is also twenty-five coins {all 4’s}.



Discussion

No Comment Found

Related InterviewSolutions