[Math] The Change-making problem algorithm proof (at the dynamic programming method)

algorithmsdynamic programmingproof-writing

I saw here the algorithm for the "Change-making problem" (at the dynamic programming method).
I saw it here: http://www.columbia.edu/~cs2035/courses/csor4231.F07/dynamic.pdf

I'm trying to find a proof for this algorithm. I try to prove it with induction but I think that it wont work at all…

I'd like if you will help me how to prove it.
If you have source at the internet it will be good to..

Thank you!

Best Answer

Given a set $D=\{d_1,\ldots,d_m\}\subset\mathbb N$ of coin denominations, for $n\in\mathbb N_0$ let $f(n)$ denote the minimum number of coins (with repetition) in $D$ needed to obtain sum $n$ (or $f(n)=\infty$ if it is ompossible). Then clearly $f(n)\ge 0$ for all $n$ and $f(n)=0\iff n=0$.

If $n>0$ and a way to obtain $n$ with $f(n)$ coins uses at least on coin of denomination $d_k$ (at least one such $k$ exists), then removing this coin we obtain a way to obtain $n-d_k$ and hence conclude $$f(n-d_k)\le f(n)-1\quad \text{for at least one $1\le k\le m$}$$ On the other hand, if $1\le k\le m$ and $n\ge d_k$ we obtain a way to obtain $n$ with $f(n-d_k)+1$ coins by adding a $d_k$ coin to an optimal way to get $n-d_k$. We conclude $$ f(n)\le f(n-d_k)+1\quad \text{for all $1\le k\le m$ with $n\ge d_k$}.$$ Together this gives us $$\tag1 f(n)=\min\{\,f(n-d_k)+1\mid 1\le k\le m,n\ge d_k\,\}\quad \text{for all $n>0$}$$ (with the $\min\emptyset=\infty$ understood). And $(1)$ together with $f(0)=0$ is precisely what the DP algorithm uses to compute $f(n)$ recursively.