lecture13Greedy

# lecture13Greedy - Greedy Algorithms Algorithm Design...

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

1 Greedy Algorithms Algorithm Design Techniques Several greedy algorithms (too many in text to cover well we will study a subset)

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

View Full Document
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
3 Making Change You need to make \$1.34 in change 1 dollar 1 quarter 1 nickel 4 pennies

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

View Full Document
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
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

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

View Full Document
6 Is this “optimal”? Define optimal Is this algorithm optimal for… US currency? Any possible currency?
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?

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

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

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## lecture13Greedy - Greedy Algorithms Algorithm Design...

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

View Full Document
Ask a homework question - tutors are online