2 then q q where q is the number of quarters used

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: 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

This document was uploaded on 02/27/2014 for the course CS 215 at SIU Carbondale.

Ask a homework question - tutors are online