GATE Computer ScienceVery hardGATE CS (PYQ pattern)

For the coin system {1, 5, 12, 25}, among the amounts 1, 2, …, 100, for how many amounts does the greedy algorithm use more coins than the optimal solution?

  1. A. 24
  2. B. 31
  3. C. 35
  4. D. 28

Correct answer: D. 28

Computing the optimal coin count by DP and the greedy count for every amount from 1 to 100 shows the two differ for 28 amounts (the first being 15: greedy uses 12 + 1 + 1 + 1 = 4 coins against 5 + 5 + 5 = 3 coins). The denomination 12 breaks the canonical property, so failures recur.

More Algorithms questions

Exams that ask this topic