02-greedy

All inputs are non negative and dollar amounts are

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Strategy: a greedy algorithm that uses the largest 9coins first Making Change Inputs: Value N of the change to be returned An unlimited number of coins of values d1, d2,.., dk Output: the smallest possible set of coins that sums to N Objective function? Smallest set Constraints on feasible solutions? Must sum to N Greedy rule: choose coin of largest value that is less than N - Sum(coins chosen so far) Always optimal? Depends on set of coin values 10 Algorithm for making change This algorithm makes change for an amount A using coins of denominations denom[1] > denom[2] > ∙∙∙ > denom[n] = 1. Input P arameters: denom, A Output P arameters: None greedy_coin_change(denom, A) { i = 1 11 while (A > 0) { Making change proof Prove that the provided making change algorithm is optimal for denominations 1, 5, and 10 Via induction, and on board --> 12 Formal proof Formal proof of the change problem Algorithm 7.1.1 is what is presented two slides previously 13 How would a failed proof work? Prove that the provided making change algorithm is o...
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.

Ask a homework question - tutors are online