Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Given an unlimited supply of coins of denominations, we wish to make change for a value ; that is, we wish to find a set of coins whose total value is . This might not be possible: for instance, if the denominations are and 10 then we can make change for 15 but not for 12. Give an dynamic-programming algorithm for the following problem.Input:,; .Question: Is it possible to make change for using coins of denominations ?

Short Answer

Expert verified

The algorithm is as follows:

Create an array of size

D0=Truefori=1 to V   Di=Falseforv=1 to V   forj=1 to V

      ifxjv         Dv=DvORDvxi      else         Dv=Falsereturn DV

Step by step solution

01

Define dynamic programming 

Dynamic programming is a paradigm used for writing algorithm which helps to solve some particular type of problems more efficiently by saving the solution of subproblems and using them to get the final solution. Rather than performing the same calculation again and again, the optimal solution to subproblems are calculated and stored.

02

Determine the subproblem

ConsiderDu as sub-problem such that u=1,.,v.

Thus, according to question,Du is true if it is possible to make change for v using coins denomination.x1,x2,xn

Du=TRUE;ifitispossibletomakechangeforvFALSE;otherwise

Now, takingDu as sub-problem, if it is possible to make change forv using denomination,x1,x2,xnthen it is also possible to make change for by using same denomination with the coin.

The desired recursion is:

Here, ‘’ is the value for which we finding denomination.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

A contiguous subsequence of a list Sis a subsequence made up of consecutive elements of S. For instance, if Sis 5,15,30,10,5,40,10

then15,30,10 is a contiguous subsequence but5,15,40 is not. Give a linear-time algorithm for the following task:Input: A list of numbers a1,a2,...,an.

Output: The contiguous subsequence of maximum sum (a subsequence of length zero has sum zero).For the preceding example, the answer would be 10,5,40,10, with a sum of 55. (Hint: For each j{1,2,...,n}, consider contiguous subsequences ending exactly at position j.)

Let us define a multiplication operation on three symbols a,b,caccording to the following table; thus ab=b,ba=c, and so on. Notice that the multiplication operation defined by the table is neither associative nor commutative.

Find an efficient algorithm that examines a string of these symbols, say bbbbac, and decides whether or not it is possible to parenthesize the string in such a way that the value of the resulting expression is . For example, on input bbbbacyour algorithm should return yes because((b(bb))(ba))c=a.

Given two strings x=x1x2···xnand y=y1y2···ym, we wish to find the length of their longest common subsequence, that is, the largest k for which there are indices i1<i2<···<ikand j1<j2<···<jkwith xi1xi2···xik=yj1yj2···yjk. Show how to do this in time 0(mn).

You are going on a long trip. You start on the road at mile post 0. Along the way there aren hotels, at mile posts a1<a2<...<an , where eachai is measured from the starting point. The only places you are allowed to stop are at these hotels, but you can choose which of the hotels you stop at. You must stop at the final hotel (at distance an), which is your destination. You’d ideally like to travel miles a day, but this may not be possible (depending on the spacing of the hotels). If you travel x miles during a day, the penalty for that day is (200x)2. You want to plan your trip so as to minimize the total penalty- that is, the sum, over all travel days, of the daily penalties.Give an efficient algorithm that determines the optimal sequence of hotels at which to stop

Time and space complexity of dynamic programming. Our dynamic programming algorithm for computing the edit distance between strings of length m and n creates a table of size n×mand therefore needs O (mn) time and space. In practice, it will run out of space long before it runs out of time. How can this space requirement be reduced?

  1. Show that if we just want to compute the value of the edit distance (rather than the optimal sequence of edits), then only O(n) space is needed, because only a small portion of the table needs to be maintained at any given time.
  2. Now suppose that we also want the optimal sequence of edits. As we saw earlier, this problem can be recast in terms of a corresponding grid-shaped dag, in which the goal is to find the optimal path from node (0,0) to node (n,m). It will be convenient to work with this formulation, and while we’re talking about convenience, we might as well also assume that is a power of 2.
    Let’s start with a small addition to the edit distance algorithm that will turn out to be very useful. The optimal path in the dag must pass through an intermediate node (k,m2) for some k; show how the algorithm can be modified to also return this value k.
  3. Now consider a recursive scheme:
    Procedure find-path((0,0)(n,m))
    Compute the value kabove
    find-path ((0,0)k,m2)
    find-path k,m2n,m
    concatenate these two paths, with kin the middle.
    Show that this scheme can be made to run inO (mn) time and O(n) space.
See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free