I am trying to solve the minimum coin change problem. The question is: Given a value V, if we want to make change for V cents, and we have infinite supply of each of C = { C1, C2, .. , Cm} valued coins, what is the minimum number of coins to make the change?
My algorithm suggested is:
Starting with an array arr[1..V],where V is the value:
For all the denominations,initialise arr[d]=1 as this is the base case. If the value == demoniation of a coin,only 1 coin is required and hence it is the least
For all values from i : 1...V: compute the minimum no of coins required to make change for a value of 'i'. 2.1. This can be done by : For all j: 1....(i-1) arr[i]=min(arr[i],arr[j]+arr[i-j]);
return arr[V];
Is this logic flawed or does it cover all cases? Most DP solutions have used a 2-D array and I don't understand why they would use O(n^2) memory space,if this exists and is correct. Thank u.