Why does the greedy coin change algorithm not work for some coin sets?

前端 未结 5 1473
灰色年华
灰色年华 2020-11-30 20:49

I understand how the greedy algorithm for the coin change problem (pay a specific amount with the minimal possible number of coins) works - it always selects the coin with t

5条回答
  •  情话喂你
    2020-11-30 21:13

    A coin system is canonical if the number of coins given in change by the greedy algorithm is optimal for all amounts.

    This paper offers an O(n^3) algorithm for deciding whether a coin system is canonical, where n is the number of different kinds of coins.

    For a non-canonical coin system, there is an amount c for which the greedy algorithm produces a suboptimal number of coins; c is called a counterexample. A coin system is tight if its smallest counterexample is larger than the largest single coin.

提交回复
热议问题