lecture13Greedy - Greedy Algorithms Algorithm Design...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Greedy Algorithms Algorithm Design Techniques Several greedy algorithms (too many in text to cover well we will study a subset)
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 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
Background image of page 2
3 Making Change You need to make $1.34 in change 1 dollar 1 quarter 1 nickel 4 pennies
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Making Change You need to make $1.34 in change 1 dollar 1 quarter 1 nickel 4 pennies Greedy algorithm: Any much as you can from largest available denomination
Background image of page 4
5 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
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Is this “optimal”? Define optimal Is this algorithm optimal for… US currency? Any possible currency?
Background image of page 6
7 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?
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 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.
Background image of page 8
9 Proving optimal Assume currency values of: 25, 10, 5, 1 Let’s prove the algorithm does work Much harder to prove than disprove
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 45

lecture13Greedy - Greedy Algorithms Algorithm Design...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online