Вы находитесь на странице: 1из 2

BC180203450

CS502- Fundamentals of Algorithms


Assignment no 3

Question: Activity selection problem.


You have given a set of activities namely a1, a2, a3……….an along with its starting
and ending time respectively. In light of the information given below in the table
form, you are required to identify (select) mutually exclusive (non- interfering) set of
activities using the given Greedy selection algorithm.
Set of activities: {a1, a2, a3………..an}
Start Time :{s1, s2, s3……………...sn}
Finish Time :{f1, f2, f3…………….fn}
Note: In this case n = 12
Activity Table:

ai 1 2 3 4 5 6 7 8 9 10 11 12

si 1 2 4 1 6 8 9 11 13 15 17 20

fi 3 5 7 8 9 10 11 14 16 18 20 24

Greedy: Activity-selector(s, f)

1. Begin
2. n=s.length
3. A [a1]
4. k 1
5. for m 2 to n
6. If s(m)>f (k)
7. A A U {am}
8. k m
9. Return A
10. End

ai 1 2 3 4 5 6 7 8 9 10 11 12

si 1 2 4 1 6 8 9 11 13 15 17 20

fi 3 5 7 8 9 10 11 14 16 18 20 24

To full fill the requirement of mutually exclusive greedy selection algorithm.


Our starting time of the next activity must be greater then the finishing time of the
previous activity.In our first activity the finishing time 3, so our next activity starting
time must be greater then the 3 that is 3th activity having starting time 4 which is
greater then the 3. So next activity are as follow, 6th ,8th 10th and 12th .

A = {a1 , a3 , a6 , a8 , a10 , a12 }

Вам также может понравиться