# Module5 - Greedy Algorithms TOPICS Greedy Strategy Activity...

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

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

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

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

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

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

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

View Full Document
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. This network can be represented by an undirected graph with
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 11/18/2009.

### Page1 / 34

Module5 - Greedy Algorithms TOPICS Greedy Strategy Activity...

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

View Full Document
Ask a homework question - tutors are online