You are on page 1of 3

King Khalid University

College of Science and arts in Tanumah

Department of Computer Science

Design and analysis of algorithms Assignment 4

Question 1:

Solve the following instance of Activities Selection problem by using


greedy methods.

Activit 1 2 3 4 5 6 7 8 9 10
y
Start 1 1 2 4 5 8 9 11 12 13
Finish 3 8 5 7 9 10 11 14 17 16

Question 2:

Consider the 5’ jobs are given with their profits and deadlines as the
following {p ,p ,..,p }= {20,15,10,5,1}, {d , d , .., d } = {2,2,1,3,3}.
1 2 5 1 2 5

a. Find the set of jobs that provides maximum profit.


Question 3:
Solve the following instance of the fractional knapsack problem by
using greedy algorithm. Where W=16

item weight value


1 10 SR 100
2 8 SR 56
3 7 SR 63
4 4 SR 12

item weight value Ratio


1 10 SR 100 10
2 8 SR 56 7
3 7 SR 63 9
4 4 SR 12 3

Sort all the items in decreasing order of their value / weight ratio-

I1 I3 I2 I4

10 9 7 3

Knapsack Items in
Cost
Weight Knapsack
16 0
6 I1 100
3 I1,I4 112

 Knapsack weight left to be filled is 3 kg but item-3 has a weight of 7 kg.


 Since in fractional knapsack problem, even the fraction of any item can be
taken.
 So, knapsack will contain the following items-
< I1,I4,(3/7)I3>

Total cost of the knapsack


= 112 + (3/7) x 9
= 112 + 3.86
= 115,86

Had the problem been a 0/1 knapsack problem, knapsack would contain the
following items:-

< I1 , I4 >

The knapsack’s total cost would be 112.

You might also like