This preview shows page 1. Sign up to view the full content.
Unformatted text preview: s Proving them correct Given a greedy algorithm, how do you show it is
optimal? As opposed to other types of algorithms (divide-andconquer , etc.) One common way is to compare the solution given
with an optimal solution 6 Making Change 7 Making change: algorithm description The problem: Give back the right amount of change, and…
Return the fewest number of coins! Inputs: the dollar-amount to return Also, the set of possible coins. (Do we have half-dollars?
That affects the answer we give.) Output: a set of coins 8 Making change: algorithm solution Problem description: providing coin change of a
given amount in the fewest number of coins Inputs: the dollar-amount to return. Perhaps the
possible set of coins, if it is non-obvious. Output: a set of coins that obtains the desired
amount of change in the fewest number of coins Assumptions: If the coins are not stated, then they
are the standard quarter, dime, nickel, and penny.
All inputs are non-negative, and dollar amounts are
View Full Document
This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.
- Spring '10