to prove the greedy solution is optimal
DESCRIPTION
greedy solutionTRANSCRIPT
![Page 1: To Prove the Greedy Solution is Optimal](https://reader036.vdocument.in/reader036/viewer/2022082423/5695d0081a28ab9b0290a462/html5/thumbnails/1.jpg)
To prove the Greedy solution is optimal:
Let X =< x1, x2. . . . . xn > denote the greedy solution vector, where xi, 0 ≤ xi≤ 1 is the fraction of Oi that is included in the knapsack. As per the description of the greedy algorithm, 0 or more of the Xi s will be 1, followed by a fractional quantity, followed by 0s. Let j be the first index such that xj != 1. Then xi = 1, i = 1, 2. . . . , j − 1 and xi = 0, i = j + 1, j + 2, . . . , n. Let Y =< y1, y2. . . . . yn > denote an arbitrary optimal solution vector. We will show that Y can be gradually transformed into X, without decreasing profitability, while maintaining feasibility.
![Page 2: To Prove the Greedy Solution is Optimal](https://reader036.vdocument.in/reader036/viewer/2022082423/5695d0081a28ab9b0290a462/html5/thumbnails/2.jpg)
Greedy Method: Task Scheduling:
Set A of tasks is independent if there exist a schedule with no late tasks. Nt (A): number of tasks in A with deadlines t or earlier,t= 1, 2, .....n
ai (task) : 1 2 3 4 5 6 7di (deadline) :4 2 4 3 1 4 6wi (weight) : 70 60 50 40 30 20 10Step1: Sort them in decreasing order of weight
![Page 3: To Prove the Greedy Solution is Optimal](https://reader036.vdocument.in/reader036/viewer/2022082423/5695d0081a28ab9b0290a462/html5/thumbnails/3.jpg)
Step2: Greedily select the task with max weightIts deadline is 4, so put it in slot 4.1 2 3 4 5 6 7a1Now select a2. Deadline is 2, so put it in slot 2.1 2 3 4 5 6 7a2 a1a3, deadline is 4. 4 is occupied, so put it in a slot less than 4, that is unoccupied and has the max value. Here 1 and 3 are unoccupied, so put it in 3. Or move backwards until u find an empty slot. If no slot found put it in the last slot.1 2 3 4 5 6 7a2 a3 a1a4, dealine is 4, so put it in 1. Thats the only unoccpied slot less than 4.1 2 3 4 5 6 7a4 a2 a3 a1a5, no empty slots less than 1...put it in 7.a6 no empty slots less than 4 put it in 6Add both the penalty's to penalty variable.a7 deadline 6, put it in 5.Finally we have1 2 3 4 5 6 7a4 a2 a3 a1 a7 a6 a5
Total Penalty 50.