DOC PREVIEW
MSU CSE 830 - Lecture9

This preview shows page 1-2-3-4 out of 13 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 13 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Greedy AlgorithmsMaking ChangeDynamic programming solutionGreedy SolutionGreedy TechniqueProof of Greedy OptimalityProof that Greedy is NOT optimalActivity selection problemPossible Greedy StrategiesEarliest end time AlgorithmProof of OptimalityShortest Interval AlgorithmProof of Optimality?Greedy Algorithms•Basic idea•Connection to dynamic programming•Proof TechniquesMaking Change•Input–Positive integer n•Task–Compute a minimal multiset of coins from C = {d1, d2, d3, …, dk} such that the sum of all coins chosen equals n•Example–n = 73, C = {1, 3, 6, 12, 24}–Solution: 3 coins of size 24, 1 coin of size 1Dynamic programming solution•Subsolutions: T(k) for 0 <= k <= n•Recurrence relation–T(n) = mini(T(n-di) + 1)–T(di) = 1–Linear array of values to compute•Compute T(k) starting at T(1) skipping bas case valuesGreedy Solution•T(n) = mini(T(n-di) + 1)•Key observation–For many (but not all) sets of coins, the optimal di will always be the maximum di–That is, T(n) = T(n-dmax) + 1 where dmax is the largest di <= n•Algorithm–Choose largest di smaller than n and recurseGreedy Technique•When trying to solve a problem, make a local greedy choice that optimizes progress towards global solution and recurse•Running time analysis is typically straightforward•Proof of optimality is harder–Based on structure of optimal solution–“Swapping” is common technique–Must consider that greedy is not optimal and consider counter-examplesProof of Greedy Optimality•Example: Any n, C = {1, 3, 9, 27, 81}•Let S be an optimal solution and G be the greedy solution•Let Ak denote the number of coins of size k in solution A•Let kdiff be the largest value of k s.t. Gk != Sk•Claim 1: Gkdiff >= Skdiff. Why?•Claim 2: Sk must contain at least 3 coins of size di for some di < dkdiff. Why?•Claim 3: We can create a better solution than Sk. How?•These three claims imply kdiff does not exist and Gk is optimal.Proof that Greedy is NOT optimal•Consider the following coin set–C = {1, 3, 6, 12, 24, 30}•Prove that greedy will not produce an optimal solution for all n•What about the following coin set?–C = {1, 5, 10, 25, 50}Activity selection problem•Input–Set of n intervals (si, fi) where •fi > si >= 0 for all intervals n•Task–Identify a maximal set of intervals that do not overlap•Example–{(0,2), (1,3), (5,7), (6, 11), (8,10)}–Solution: {(1,3), (5,7), (8,10)}Possible Greedy Strategies•Choose the shortest interval and recurse•Choose the interval that starts earliest and recurse•Choose the interval that ends earliest and recurse•Choose the interval that starts latest and recurse•Choose the interval that ends latest and recurse•Do any of these strategies work?Earliest end time Algorithm•Sort intervals by end time•A: Choose the interval with the earliest end time breaking ties arbitrarily•Prune intervals that overlap with this interval and goto A •Running time?Proof of Optimality•For any instance of the problem, there exists an optimal solution that includes an interval with earliest end time–Let S be an optimal solution–Suppose S does not include an interval with the earliest end time–We can swap the interval with earliest end time in S with an interval with earliest overall end time to obtain feasible solution S’–S’ has at least as many intervals as S and the result follows•We recursively apply this observation to the subproblem induced by selecting an interval with earliest end time to see that greedy produces an optimal scheduleShortest Interval Algorithm•Sort intervals by interval length•A: Choose the interval with shortest length breaking ties arbitrarily•Prune intervals that overlap with this interval and goto A •Running time?Proof of Optimality?•For any instance of the problem, there exists an optimal solution that includes an interval with earliest end time–Let S be an optimal solution–Suppose S does not include a shortest interval –Can we produce an equivalent solution S’ from S that includes a shortest interval?–If not, how does this lead to a


View Full Document

MSU CSE 830 - Lecture9

Download Lecture9
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture9 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture9 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?