chap16-solutions - Selected Solutions for Chapter 16:...

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

View Full Document Right Arrow Icon
Selected Solutions for Chapter 16: Greedy Algorithms Solution to Exercise 16.1-4 Let S be the set of n activities. The “obvious” solution of using GREEDY-ACTIVITY-SELECTOR to find a maxi- mum-size set S 1 of compatible activities from S for the first lecture hall, then using it again to find a maximum-size set S 2 of compatible activities from S N S 1 for the second hall, (and so on until all the activities are assigned), requires ‚.n 2 / time in the worst case. Moreover, it can produce a result that uses more lecture halls than necessary. Consider activities with the intervals f Œ1; 4/; Œ2; 5/; Œ6; 7/; Œ4; 8/ g . GREEDY-ACTIVITY-SELECTOR would choose the activities with intervals Œ1; 4/ and Œ6; 7/ for the first lecture hall, and then each of the activities with intervals Œ2; 5/ and Œ4; 8/ would have to go into its own hall, for a total of three halls used. An optimal solution would put the activities with intervals Œ1; 4/ and Œ4; 8/ into one hall and the activities with intervals Œ2; 5/ and Œ6; 7/ into another hall, for only two halls used. There is a correct algorithm, however, whose asymptotic time is just the time needed to sort the activities by time— O.n lg n/ time for arbitrary times, or pos- sibly as fast as O.n/ if the times are small integers. The general idea is to go through the activities in order of start time, assigning each to any hall that is available at that time. To do this, move through the set of events consisting of activities starting and activities finishing, in order of event time. Maintain two lists of lecture halls: Halls that are busy at the current event- time t (because they have been assigned an activity i that started at s i ± t but won’t finish until f i > t ) and halls that are free at time t . (As in the activity- selection problem in Section 16.1, we are assuming that activity time intervals are
Background image of page 1

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

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

This note was uploaded on 04/20/2010 for the course IE ie200 taught by Professor . during the Spring '10 term at 카이스트, 한국과학기술원.

Page1 / 3

chap16-solutions - Selected Solutions for Chapter 16:...

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

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