File 2
File 2
I;¬{0,1}
Maximize i=1 subject to i=l
Maximize the sum of the values of the items in the knapsack so that the sum of the weights must be less
than the knapsack's capacity.
Greedy algorithm for knapsack
AlgorithmGreedyKnapsack(m,n)
l p[i:n] and [1:n] contain the profits and weights respectively
/ if the n-objects ordered such that p[iJ/w[i]=p[i+l/w[i+1], m> size of knapsack and
x[l:n]’ the solution vector
(0, 1, Va )
1x15+xl0 - 20 12451s- 31.5
(Ya, Va, Ye ) Vhx 18+%x15+ Va x10 = 16. 5 ½ x 25+% x24+ V x15 =
12.5+8+3.75 - 24.25
Analysis: - If we do not consider the time considered for sorting the inputs then all of the
three greedy strategies complexity will be O(n).
The value of a feasible solution J is the sum of the profits of the jobs in J, ie., jejP;