Unformatted text preview: ’ 10 = 7 cents. 3.â€¯ Choose a nickel, leaving 7 â€“ 5 = 2 cents. 4.â€¯ Choose a penny, leaving 1 cent. Choose another penny leaving 0 cents. In total, it requires 6 coins. Greedy Change Making Algorithm Solution: greedy change making algorithm for n cents. The algorithm works with any coin denominations c1, c2, â€¦,cr . procedure change (c1, c2, â€¦, cr: values of coins, where c1> c2> â€¦ > cr ; n: a positive integer) for i := 1 to r di := 0 while n â‰¥ ci di := di + 1 n = n  ci Â—à¼‰â€¯ For the example of US currency, we may have quarters, dimes, nickels and pennies, with c1 = 25, c2 = 10, c3 = 5, and c4 = 1. Proving Op$mality for US Coins Lemma 1: if n is a positive integer, n cents in change using quarters, dimes, nickels, and pennies,...
View
Full Document
 Spring '14
 M.Nojoumian
 Algorithms, Sort

Click to edit the document details