Module5 - Greedy Algorithms TOPICS Greedy Strategy Activity...

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

View Full Document Right Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 1 Greedy Algorithms TOPICS •Greedy Strategy •Activity Selection Minimum Spanning Tree •Shortest Paths •Huffman Codes •Fractional Knapsack Chapter 5 Algorithm Design Kleinberg and Tardos
Image of page 1

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

View Full Document Right Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 2 The Greedy Principle The problem: We are required to find a feasible solution that either maximizes or minimizes a given objective solution . It is easy to determine a feasible solution but not necessarily an optimal solution. The greedy method solves this problem in stages, at each stage, a decision is made considering inputs in an order determined by the selection procedure which may be based on an optimization measure. The greedy algorithm always makes the choice that looks best at the moment. For each decision point in the greedy algorithm, the choice that seems best at the moment is chosen It makes a local optimal choice that may lead to a global optimal choice.
Image of page 2
11/19/09 CSE 5311 Spring 2007 M Kumar 3 Activity Selection Problem Scheduling a resource among several competing activities. S = {1,2, 3, …, n } is the set of n proposed activities The activities share a resource, which can be used by only one activity at a time -a Tennis Court, a Lecture Hall etc., Each activity i has a start time, s i and a finish time f i , where s i f i . When selected, the activity takes place during time ( s i , f i ) Activities i and j are compatible if s i f j or s j f i The activity-selection problem selects the maximum-size set of mutually compatible activities The input activities are in order by increasing finishing times. f 1 f 2 f 3 f n ; Can be sorted in O ( n log n ) time
Image of page 3

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

View Full Document Right Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 4 Procedure for activity selection (from CLRS) Procedure GREEDY_ACTIVITY_SELECTOR( s, f ) n length [ S ]; in order of increasing finishing times; A {1}; first job to finish j 1; for i 2 to n do if s i f j then A A { i }; j i ;
Image of page 4
11/19/09 CSE 5311 Spring 2007 M Kumar 5 i s i f i 1 1 4 2 3 5 3 0 6 4 5 7 5 3 8 6 5 9 7 6 10 8 8 11 9 8 12 10 2 13 11 12 14 Initially we choose activity 1 as it has the least finish time. Then, activities 2 and 3 are not compatible as s 2 < f 1 and s 3 < f 1 . We choose activity 4, s 4 > f 1 , and add activity 4 to the set A. A = {1, 4} Activities 5, 6, and 7 are incompatible and activity 8 is chosen A = {1,4,8} Finally activity 10 is incompatible and activity 11 is chosen A {1,4,8,11} The algorithm can schedule a set of n activities in Θ (n) time.
Image of page 5

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

View Full Document Right Arrow Icon
11/19/09 CSE 5311 Spring 2007 M Kumar 6 Minimum-Cost Spanning Trees Consider a network of computers connected through bidirectional links. Each link is associated with a positive cost: the cost of sending a message on each link.
Image of page 6
Image of page 7
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