Coin Changing Problems

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Coin Changing Problem

Overview:
The Coin Changing Problem is a classic optimization problem that involves finding the
minimum number of coins needed to make a certain amount of change. This problem is
commonly addressed using dynamic programming techniques.
Problem Statement:
Given a set of coin denominations and a target amount, the goal is to find the minimum
number of coins required to make up that amount. Each coin denomination can be used an
unlimited number of times.
Dynamic Programming Solution:
1. Define Subproblems:
Let dp[i] represent the minimum number of coins needed to make change for the amount . i

2. Formulate the Recurrence Relation:


The recurrence relation is given by:
dp[i] = minf or all coin denominations j(dp[i − coin[j]] + 1)

This formula states that the minimum number of coins needed to make change for the
amount is the minimum of the number of coins needed to make change for
i for i − coin[j]

each coin denomination , plus one (for using one coin of denomination ).
j j

3. Base Case:
dp[0] = 0

The base case indicates that no coins are needed to make change for the amount 0.
4. Build the Table (Bottom-Up Approach):
The table is built in a bottom-up manner, starting from the base case
dp dp[0] up to the
target amount.
5. Extract the Solution:
The final result is given by dp[target amount] , representing the minimum number of coins
needed.
Example:
Consider the coin denominations and a target amount of 11.
[1, 2, 5]

1. Define Subproblems:
dp[i]represents the minimum number of coins needed to make change for the
amount . i

2. Recurrence Relation:
dp[i] = minf or all coin denominations j(dp[i − coin[j]] + 1)

3. Base Case:
dp[0] = 0

4. Build the Table:


Amount 0 1 2 3 4 5 6 7 8 9 10 11

Min Coins 0 1 1 2 2 1 2 2 3 3 2 3
5. Extract the Solution:
The minimum number of coins needed to make change for 11 is 3.
Conclusion:
The Coin Changing Problem is efficiently solved using dynamic programming principles.
The table stores the optimal solutions to subproblems, leading to a solution that
dp

minimizes the number of coins needed for any given amount.

Note: The example uses a bottom-up dynamic programming approach. Other variations,
such as top-down with memoization, are also applicable.

You might also like