lecture14GreedyDesign2

# lecture14GreedyDesign2 - 1 Greedy Algorithms • Algorithm...

This preview shows pages 1–14. Sign up to view the full content.

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

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

Unformatted text preview: 1 Greedy Algorithms • Algorithm Design Techniques • Several greedy algorithms 2 The point is, ladies and gentleman, that greed-- for lack of a better word -- is good . Greed is right. Greed works. Greed clarifies, cuts through, and captures the essence of the evolutionary spirit. Greed, in all of its forms -- greed for life, for money, for love, knowledge -- has marked the upward surge of mankind. Gordon Gecko in the movie “Wall Street” 3 Greedy Algorithms • Used to solve optimization problems – Multiple solutions exist, need to find the ‘best’ one • Make the choice that looks best at the moment • A locally optimal choice at each step in expectation of achieving global optimum • Does not always yield optimal solutions • Usually simple and fast 4 Making Change • You need to make \$1.34 in change – 1 dollar – 1 quarter – 1 nickel – 4 pennies 5 Making Change • You need to make \$1.34 in change Goal: minimize the number of coins – 1 dollar – 1 quarter – 1 nickel – 4 pennies • Greedy algorithm: – As much as you can from largest available denomination 6 Greedy vs. Non-greedy • Greedy – 1.00 + 0.25 + 0.05 + 4 * 0.01 = 7 coins • Non-greedy – 4 * 0.25 + 3 * 0.10 + 4 * 0.01 = 11 coins 7 Is this “optimal”? • Define optimal • Is this algorithm optimal for… – US currency? – Any possible currency? 8 Proving not optimal • Let a currency exist with the following coin values: – 5, 4, 1 • Assertion: Algorithm is not optimal for this currency How to prove this? 9 Proving not optimal • Let a currency exist with the following coin values: – 5, 4, 1 • What’s a change request where the greedy algorithm fails? You can disprove with an example. 10 Proving optimal • Assume currency values of: – 25, 10, 5, 1 – Let’s prove the algorithm does work • Much harder to prove than disprove 11 Assertion 1 • If x is the largest coin such that x ≤ n, then there exists an optimum solution containing x. – This is a greedy choice property • Proof: Let A be an optimal solution – If n < 5, then x = 1. Clearly only one solution – If 5 ≤ n < 10 then x = 5. If A does not contain the greedy choice 5, then it contains 5 1’s, which can be replaced by 1 5, so it’s not an optimal solution. – Similar argument applies for 10 ≤ n < 25 – Continued… 12 Cont… • If 25 ≤ n then x=25. Assume A does not contain a 25. – If A contains at least 3 10’s, they can be traded for 25 + 5 – Otherwise, A consists of 10’s, 5’s, and 1’s and must contain some subset = 25 (why?), which we can replace with a 25 – The assertion is proven for all cases. 13 Assertion 2 • The greedy choice x, followed by an optimal solution for n-x, is optimal – Let B be an optimal solution for n-x, Assume B ∪ {x} is not optimal. Let C ∪ {x} be a better solution, which means that |C|<|B|, but C can’t be smaller than B, so we are done....
View Full Document

## This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

### Page1 / 75

lecture14GreedyDesign2 - 1 Greedy Algorithms • Algorithm...

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

View Full Document
Ask a homework question - tutors are online