Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I modify the Activity Selection Problem so that instead of always selecting the first activity to finish (activity selection problem in the text

How can I modify the Activity Selection Problem so that instead of always selecting the first activity to finish (activity selection problem in the text CLRS16.1), we instead select the last activity to start that is compatible with all previously selected activities. DESCRIBE how this approach is a greedy algorithm, and PROVE that it yields an optimal solution.

Please help!!! The original solution and explanation of the activity selection problem is below

image text in transcribed

161 An activity-selection problem 421 The procedure GREEDY-ACTIVITY-SELECTOR is an iterative version of the pro- cedure RECURSIVE-ACTIVITY-SELECTOR. It also assumes that the input activi- ties are ordered by monotonically increasing finish time. It collects selected activ- ities into a set A and returns this set when it is done. GREEDY-ACTIVITY-SELECTOR(s, f) 1 n = s.length 2 A = {a} 3 k = 1 4 for m = 2 ton 5 if s[m] = f[k] 6 A = AU{m} 7 k = m 8 return A The procedure works as follows. The variable k indexes the most recent addition to A, corresponding to the activity af in the recursive version. Since we consider the activities in order of monotonically increasing finish time, fx is always the maximum finish time of any activity in A. That is, fk = max {fi:a; A} (16.3) Lines 23 select activity an, initialize A to contain just this activity, and initialize k to index this activity. The for loop of lines 47 finds the earliest activity in Sk to finish. The loop considers each activity am in turn and adds am to A if it is compat- ible with all previously selected activities, such an activity is the earliest in Sk to finish. To see whether activity am is compatible with every activity currently in A, it suffices by equation (16.3) to check (in line 5) that its start time sm is not earlier than the finish time fk of the activity most recently added to A. If activity am is compatible, then lines 67 add activity am to A and set k tom. The set A returned by the call GREEDY-ACTIVITY-SELECTOR(s, f) is precisely the set returned by the call RECURSIVE-ACTIVITY-SELECTOR (s. f.0,n). Like the recursive version, GREEDY-ACTIVITY-SELECTOR schedules a set of n activities in (n) time, assuming that the activities were already soited initially by their finish times

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

What are the skills of management ?

Answered: 1 week ago