Coin Changing Problem
Given an infinite number of different domination coins, calculate the number of ways of representing n rupees
Solution :
- One simple ways try to make N money with M type of coins this ways
- N money with M-1 types of coins +
- N – Amount[M] with M types of coins
Recursive Algorithm:
- If
money == 0
then- return 1 (i.e. only way to make money 0 with any kind of coins)
- If
index >= total
coins thenreturn 0
- Iterate till computedAmount <= money
- recursively call to make computedAmount with M-1 coins
- remaining amount with with N coins
Latest Source Code:
Github: CoinChangingProblem.java
Output:
Total ways (recursive): 5 Total ways (with memo): 5