0% found this document useful (0 votes)
39 views2 pages

M1 Greedy - Activity Selection Problem

The activity selection problem is a mathematical optimization challenge focused on scheduling resources for multiple activities without overlap. A greedy algorithm is proposed to select the maximum set of compatible activities based on their start and finish times. The document includes an example with ten activities, demonstrating the selection process and the final chosen activities.

Uploaded by

luckymlcvl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

M1 Greedy - Activity Selection Problem

The activity selection problem is a mathematical optimization challenge focused on scheduling resources for multiple activities without overlap. A greedy algorithm is proposed to select the maximum set of compatible activities based on their start and finish times. The document includes an example with ten activities, demonstrating the selection process and the final chosen activities.

Uploaded by

luckymlcvl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Activity Selection Problem

Thursday, December 1, 2022 8:25 PM

• The activity selection problem is a mathematical optimization problem.


• Our first illustration is the problem of scheduling a resource among several challenge
activities.
• We find a greedy algorithm provides a well designed and simple method for selecting a
maximum- size set of manually compatible activities.

• Suppose S = {1, 2....n} is the set of n proposed activities.


• The activities share resources which can be used by only one activity at a time, e.g.,
Tennis Court, Lecture Hall, etc.
• Each Activity "i" has start time si and a finish time fi, where si ≤fi.
• If selected activity "i" take place meanwhile the half-open time interval [si,fi].
• Activities i and j are compatible if the intervals (si, fi) and [sj, fj] do not overlap.
• i.e. i and j are compatible if sj ≥fi or si ≥fj.
• The activity-selection problem chosen the maximum- size set of mutually consistent
activities.

Algorithm Of Greedy- Activity Selector:


GREEDY- ACTIVITY SELECTOR (s, f)
1. n ← length [s]
2. A ← {1}
3. j ← 1.
4. for i ← 2 to n
5. do if si ≥ fi
6. then A ← A ∪ {i}
7. j ← i
8. return A

Example: Given 10 activities along with their start and end time as
S = (A1 A2 A3 A4 A5 A6 A7 A8 A9 A10)
Si = (1,2,3,4,7,8,9,9,11,12)
fi = (3,5,4,7,10,9,11,13,12,14)

Solution:

Arranging the activities in increasing order of end time / finish time

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Accept the Activity whose start time >= finish time of Selected Activity

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Greedy Technique Page 1


A1 is selected first. We must consider activities from left to right.

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Selected (A1, A3) 3>=3

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Selected (A1, A3, A4) 4>=4

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Selected (A1, A3, A4, A6) 8>=7

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Selected (A1, A3, A4, A6, A7) 9>=9

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Selected (A1, A3, A4, A6, A7, A9) 11>=11

Activity A1 A3 A2 A4 A6 A5 A7 A9 A8 A10
Start 1 3 2 4 8 7 9 11 9 12
Finish 3 4 5 7 9 10 11 12 13 14

Selected (A1, A3, A4, A6, A7, A9, A10) 12>=12

Final selected Activities (A1, A3, A4, A6, A7, A9, A10).

Greedy Technique Page 2

You might also like