Question: Tackle this problem using the dynamic programming technique. The problem that we will consider is the so called coin changing problem . Consider the problem
Tackle this problem using the dynamic programming technique. The problem that we will consider is the so called coin changing problem Consider the problem of developing an algorithm that will
determine how many of each type of coin,such as quarters, dimes and so forth, it
takes to equal the given amount such that the number of coins used is minimal.
Let us assume that the coins available are dollars, quarters, dimes,
nickels and pennies only. For example, cents can be changed to quarters and
two pennies. The number of coins used is and you should convince yourself that we
can not total cents with less than coins.
To tender change for a given amount with the minimum number of coins we would
first like to give out as many quarters as possible. For the remaining amount we would
like to give out as many dimes as possible, and so on Finally we hand out pennies for
whats left. This method comes naturally and instinctively to us We may have done
it before without realizing that we were handing out the minimum possible number
of coins for the amount in question. Computer scientists call this method the greedy
method. The basic method
is to grab as much as possible at every step in the solution.
As we proved in class, with the given values for the coins, this greedy algorithm
always produces an optimal solution to our problem. However, with a different series
of values for the coins, the greedy algorithm may not work.
Suppose the country of Weirdonia has three types of coins worth cent, cents
and cents. To make up an amount of cents, the greedy algorithm would use
coins coins of cents each and coins of cent each One could actually do
better, by using coins of cents each.
We can develop an algorithm using dynamic programming that always works, no
matter what the values of the coins are. You are going to do that for this problem.
But, I will guide you through the process so that you dont get overwhelmed.
Suppose the currency we are using has available coins of n different denominations.
Let a coin of denomination i i n have value di We assume that each di
Further, we assume that the denominations are presented to us in increasing order
ie d d d dn Finally, we assume that d is so that it is feasible
to make up any amount. Let m be the amount for which we want to determine the
minimal num of coins needed.
Define ci j to be the minimum number of coins required to pay an amount of j
units, j m using only coins of denomination to i i
Design an improvised recursive algorithm to solve the same problem that ensures
that no subproblem is solved more than once. Basically maintain an appropriate
table and use the memoization technique. This is also sometimes called as the
top down approach. Pts
In practice, even when there are no repeated subproblems recursive implemen
tations involves considerable overhead as the system has to set up stack space
etc. Hence, nonrecursive implementations are often preferred even if the worst
case complexity is the same. Design an algorithm using the bottom up approach
for solving the same problem using the dynamic programming technique.
Illustrate the operation of your bottom up algorithm by means of the following
example. The different denominations available are cent, cents and cents.
The amount that we are concerned with is cents. Show, the entire table and
do not just give me the final answer.
What is the complexity of your bottom up algorithm? Is this a polynomial time
algorithm or not? If so why so and If not, why not? Pts
Assuming that the table Cnm is already built, devise an algorithm to
determine an optimal solution to the coin changing problem. Note that the
algorithms that you developed in the previous part only computed the value
of an optimal solution and not an optimal solution itself. Specifically, your
algorithm should output an integer array Xn with the property that Xi
is the number of coins of ith denomination that could be used while disbursing
an amount of m cents optimally. Pts
What is the complexity of the algorithm that you designed to produce an opti
mal solution? Pts
Normally speaking, the bottom up algorithms are preferred as they dont involve
the overhead of recursion. However, for this problem there is an important dis
advantage of the bottom up algorithm in comparison to the top down algorithm.
Can you identify and elucidate it Pts
to make up any amount. Let m be the amount for which we want to determine the
minimal number of coins needed.
Define cij to be the minimum number of coins required to pay an amount of j
units, j m using only coins of denominations to i i n Now, carry
out the following steps.
Develop a recurrence relation for cij by analyzing the structure of the opti
mal solution. You need to specify clearly the recurrence relation and the base
condition. Y
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
