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 NOT produce an optimal answer?(a) 20(b) 12(c) 6(d) 5I have been asked this question in an online interview.I'd like to ask this question from Coin Change Problem in division Dynamic Programming of Data Structures & Algorithms II

Answer»

The CORRECT option is (c) 6

Explanation: 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}.



Discussion

No Comment Found

Related InterviewSolutions