User:Mathwizard1232/roughdraft/Greedy Coin Proof

Proof that a Greedy Coin Algorithm is optimal
Let there be a coin denominations $$x_i$$ which are sorted from lowest to highest with i starting at 0 and going to n. Then for any given amount of money $$m$$, there exists an optimal selection of coins $$O(i)$$ where for any i, O(i) = the number of coins of denomination $$x_i$$ and there exists no group of coins with the same value $$m$$ and fewer elements, $$\sum_0^n O(i)$$.

Algorithm: Let the distribution of coins be C(i). For each i starting with 0 and ending with n, do:
 * 1) Set $$C(i) = \lfloor \frac{m- \sum_{k=0}^{i-1}{C(k) x_k}}{x_i} \rfloor$$.
 * 2) Let the remaining amount to be distributed be $$r = m - \sum_{k=0}^i{C(k) x_k}$$.
 * 3) While there exists combinations of r and smaller coins such that $$\{0,1,\cdots,r-1,r\} + \sum_{k=0}^{i-1}{\{0,1,\cdots,C(k)-1,C(k)\}x_k} = x_i$$, increase C(i) by one and replace the corresponding coins by decreasing the appropriate C(k) and decreasing the remainder such that the value of the expression $$r + \sum_{k=0}^i C(k) x_k$$ remains unchanged.

Claim: $$\forall i C(i) = O(i)$$

Proof by contradiction. $$\forall i$$, if O(i) < C(i), then the value must have been distributed to a coin $$l > 0\,\!$$. There must be a combination such that $$\{0,1,\cdots,r-1,r\} + \sum_{k=0}^{l-1}{\{0,1,\cdots,C(k)-1,C(k)\}x_k} = x_l$$. But if there were such a combination, then it would no longer exist in the final C because C(l) would have been incremented and the combination involving $$x_0$$ coins would no longer exist. Therefore, $$O(i) \ge C(i)$$.

If $$\exists i O(i) > C(i)$$, then $$\sum_0^n O(i) > \sum_0^n C(i)$$. But by definition, there can be no distribution with fewer elements than O(i). Therefore, $$\forall i C(i) = O(i)$$.