module5 - 9/21/09 CSE 5311 Fall 2007 M Kumar 1 Greedy...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 9/21/09 CSE 5311 Fall 2007 M Kumar 1 Greedy Algorithms TOPICS •Greedy Strategy •Activity Selection •Minimum Spanning Tree •Shortest Paths •Huffman Codes •Fractional Knapsack 9/21/09 CSE 5311 Fall 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 9/21/09 CSE 5311 Fall 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. 9/21/09 CSE 5311 Fall 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 9/21/09 CSE 5311 Fall 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 ; 9/21/09 CSE 5311 Fall 2007 M Kumar 5 • i s i f i • 1 1 4 • 2 3 5 • 3 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....
View Full Document

This document was uploaded on 11/18/2009.

Page1 / 36

module5 - 9/21/09 CSE 5311 Fall 2007 M Kumar 1 Greedy...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online