Introduction to Algorithms, Second Edition

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
The University of Texas at Austin Lectures 11-14 Department of Computer Sciences Professor Vijaya Ramachandran Greedy, MST CS357: ALGORITHMS, Spring 2006 1 The Greedy Framework Rcall that an optimization problem is one for which an input has a collection of feasible solutions, each with an associated cost, and we need to find a feasible solution that optimizes the cost; here ‘optimizes’ would mean either minimizes or maximizes , depending on the nature of the problem. Such a solution is called an optimal solution. A greedy strategy for an optimization problem constructs an optimal solution (which is typ- ically a set of elements) incrementally by making a locally optimal choice at each step to decide the next element to be added to the solution. If this strategy generates an optimal solution, then this represents a greedy algorithm . 2 A Toy Problem Activity Selection Problem Given a collection of activities S = { ( s i , f i ), 1 i n } , where s i and f i are the start and finish times of the i th activity, and f 1 f 2 ≤ · · · ≤ f n , a feasible solution is a subset of activities whose durations do not overlap. A feasible solution with the maximum number of activities is an optimal solution . Algorithm Greedy Activity Selection Start with an initially empty solution A . Let T := S repeat Select an activity α in T with smallest finish time and set A := A ∪ { α } . Delete from T those activities whose durations overlap with the selected activity. until T = φ Correctness Lemma 1 (Greedy Choice) : Let X be a subset of an optimal solution for the activity selection problem on S . Let S be the set of activities in S that do not overlap with any activity in X , and let α = ( s, f ) be the activity with smallest finish time in S . Then, X = X ∪ { α } is a subset of an optimal solution for S .
Image of page 1

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

View Full Document Right Arrow Icon
Proof. Clearly X is a feasible solution since none of the activities in X overlap with one another. Consider an optimal solution A for S that contains X . (We are given that such an optimal solution exists.) If A contains α then we are done. Otherwise let β = ( s , f ) be the activity with smallest finish time in A X . Then, f > f since ( s, f ) is the activity with smallest finish time that does not overlap with any activity in X . Since α is in S , it does not overlap with any activity in X . Also, α does not overlap with any activity in A X − { β } since any activity in A X − { β } must have a start time greater than f and the finish time f of α is smaller than f . Hence α does not overlap with any activity in A − { β } .
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern