0% found this document useful (0 votes)
62 views3 pages

To Prove The Greedy Solution Is Optimal

The document outlines a greedy algorithm for task scheduling that sorts tasks by decreasing weight and assigns each task to the earliest slot that meets its deadline. It provides an example of applying this greedy algorithm to a set of 7 tasks with various weights and deadlines, showing the scheduling that results and calculating the total penalty of 50. The greedy approach aims to maximize weight by prioritizing tasks with higher weights at each step.

Uploaded by

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

To Prove The Greedy Solution Is Optimal

The document outlines a greedy algorithm for task scheduling that sorts tasks by decreasing weight and assigns each task to the earliest slot that meets its deadline. It provides an example of applying this greedy algorithm to a set of 7 tasks with various weights and deadlines, showing the scheduling that results and calculating the total penalty of 50. The greedy approach aims to maximize weight by prioritizing tasks with higher weights at each step.

Uploaded by

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

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 rst 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 protability, while maintaining
feasibility.

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 7
di (deadline) :4 2 4 3 1 4 6
wi (weight) : 70 60 50 40 30 20 10

Step1: Sort them in decreasing order of weight


Step2: Greedily select the task with max weight
Its deadline is 4, so put it in slot 4.
1234567
a1
Now select a2. Deadline is 2, so put it in slot 2.
1234567
a2 a1
a3, 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
nd an empty slot. If no slot found put it in the last slot.
1234567
a2 a3 a1
a4, dealine is 4, so put it in 1. Thats the only unoccpied slot less than 4.
1234567
a4 a2 a3 a1
a5, no empty slots less than 1...put it in 7.
a6 no empty slots less than 4 put it in 6
Add both the penalty's to penalty variable.
a7 deadline 6, put it in 5.
Finally we have
1234567
a4 a2 a3 a1 a7 a6 a5
Total Penalty 50.

You might also like