Data Structures & AlgorithmsHardTCS NQT · GATE CS

A coin-change problem uses coins {1, 3, 4} and asks for the minimum number of coins for each amount. Which statement is correct?

  1. A. Greedy is always optimal for any set of coin denominations
  2. B. Greedy always fails for any set with more than two coins
  3. C. The DP needs O(amount²) time, so greedy must be used instead
  4. D. Greedy (largest coin first) can fail: for amount 6 it gives 3 coins while 3 + 3 uses 2

Correct answer: D. Greedy (largest coin first) can fail: for amount 6 it gives 3 coins while 3 + 3 uses 2

For canonical systems greedy works, but {1, 3, 4} is not canonical: 6 = 4 + 1 + 1 uses three coins while 3 + 3 uses two. The DP over amounts is O(amount × number of coins), so it is not a reason to prefer greedy.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic