Assignment 08 - Greedy Algorithm (Solution)

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

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

This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.

Page1 / 2

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

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online