{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment 08 - Greedy Algorithm (Solution)

Assignment 08 - Greedy Algorithm (Solution) - The Hong Kong...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
The Hong Kong University of Science & Technology COMP 271: Design and Analysis of Algorithms Fall 2007 Solution to Assignment 8 Question 1 : In Hong Kong, coins are minted with denominations of 1, 2, 5 and 10 cents. Suppose there is a country where coins are minted with denominations of { d 1 ,d 2 , · · · ,d k } units. Consider the problem of making change of n units using the minimum number of coins. A greedy algorithm is to repeatedly use the biggest coin smaller than the amount to be changed unit it is zero. 1. Show that the greedy algorithm does not always give the minimum number of coins in a country whose denominations are { 1 , 6 , 10 } . 2. Show that the greedy algorithm does give the minimum number of coins for Hong Kong. Solution: 1. To make change for n = 12 Greedy uses 3 coins, i.e., { 10 , 1 , 1 } . However, the best way of making change only used 2 coins, i.e., { 6 , 6 } . 2. Suppose that the problem of making change of n units using the minimum number of coins in HK has the following solution: the number of 1, 2, 5, 10 cents are respectively
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern