Solution: Coin Change Problem
Understand different approaches to solve the coin change problem, including brute force, memoization, tabularization, and optimized solutions. Learn how dynamic programming improves efficiency by reducing repeated computations and how space optimization can further enhance the solution.
Solution #1: Brute force
Explanation
To count the total number of solutions, we divide the solution into two sets: one subset does not contain the coin currently being evaluated, and the other subset contains at least one coin of that denomination.
However, notice that the function above recomputes the same subproblem several times.
Time complexity
The time complexity of this solution is in . Why? Because for every coin, we have 2 options: to either include it or exclude it. So, if we think in terms of binary, it’s 0 to exclude or 1 to include every coin. For example, if we have 2 coins, the options will be 00, 01, 10, 11, which is 4 or options. Therefore, extrapolating to ...