Question

A greedy algorithm is used to make change for a given amount using a set of coin denominations. For denominations {1, 5, 10, 25} and an amount of 30, it works correctly. However, for denominations {1, 4, 6} and an amount of 8, it fails to find the optimal solution (e.g., 4+4 vs 6+1+1). What is the fundamental reason for this failure, which is a common debugging point for greedy algorithms?

A The algorithm does not sort the coin denominations.
B The problem does not satisfy the greedy choice property.
C The base case for the recursion is incorrect.
D The algorithm uses a stack instead of a queue.
E The input amount is too small for the greedy approach.
Practice Next

Hey! Ask a query