Question: The problem that we will consider is the so called coin changing problem that we discussed in class. Consider the problem of developing an algorithm
The problem that we will consider is the so called coin changing problem that
we discussed in class. 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.
To begin with 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. It is no surprise that such a method comes naturally to us humans!. The greedy method is often employed to solve many an apparently intractable problems in computer science and you would be surprised how often it works. 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 number 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 denominations to i i n Now, carry
out the following steps.
Develop a recurrence relation for ci j by analyzing the structure of the opti
mal solution. You need to specify clearly the recurrence relation and the base
condition. You should also justify as to why they are correct. Pts
Using the recurrence relation developed, write a simple recursive algorithm to
compute ci j Note that, by simply calling this recursive algorithm with pa
rameters n and m we can determine the minimum number of coins needed to
pay an amount of m units using the available coins of n different denominations.
Pts
The English coinage before decimalization included halfcrowns pence
florins pence shillings pence sixpences pence and pennies. The
coinage also included several other coins such as farthing and three pence, but
we will ignore them to limit the number of denominations to Suppose, I want
to dispense an amount of pence using the coinage of different denomina
tions, we will call your recursive program with parameters Draw the
complete recursion tree generated by this call. For each node in the tree, sim
ply write the parameters of that recursive call. c will be the root of the
recursion tree. Observe that it involves lots of repeated subproblems. Clearly,
mark the repeated subproblems in your recursion tree. If a bigger subproblem is
repeating, do not worry about marking the repetitions of the subsubproblems
of that bigger subproblem. Pts
Typically the simple implementation would have terrible computational com
plexity as it involves solving repeated subproblems. Dynamic programming
method is to avoid doing solving repeated subproblems and in this part you
will build an implementation for the coin changing problem using the dynamic
programming technique.
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
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
