July 2018
Beginner
202 pages
5h 4m
English
Scenario
In this activity, we will be building a dynamic programming algorithm to solve the coin change problem. Given a value, N, if we want to split it into coins, and we have an infinite supply of each of S={S1, S2, …, Sm} valued coins, in how many ways can we do it? The order of the coins doesn't matter. For N = 4 and S = {1, 2, 3}, there are four solutions: {1, 1, 1, 1}, {1, 1, 2}, {2, 2}, and {1, 3}, so the result should be four.
Aim
To solve the coin change problem as described previously using a dynamic programming algorithm.
Prerequisites
You need to implement the ways() method of the CoinChange class, which returns the number of ways to produce a given change for amount N, given a set of coins. ...
Read now
Unlock full access