Lecture 5 A
Lecture 5 A
Exam study
Party!
CS4335 HW
Max
Project lateness
=2
0 0 0 0 2
Party! Exam study CS4335 HW Term paper Project
d3 = 9 d2 = 8 d6 = 15 d1 = 6 d5 = 14 d4 = 9
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Page 11
Minimizing Lateness: Greedy Algorithms
• Greedy template. Consider jobs in some order.
l1=0, l2=1 1 2
l1=9, l2=0
tj 1 10
0 1 11 dj 2 10
counterexample
Page 13
Minimizing Lateness: Greedy Algorithm
• Greedy algorithm. Earliest deadline first.
Sort n jobs by deadline so that d1 d2 …
dn
t 0
for j = 1 to n 1 2 3 4 5 6
d1 = 6 d2 = 8 d3 = 9 d4 = 9 d5 = 14 d6 = 15
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Page 14
Minimizing Lateness: No Idle Time
• Observation. There exists an optimal schedule
with no idle time.
d=4 d=6 d = 12
0 1 2 3 4 5 6 7 8 9 10 11
d=4 d=6 d = 12
0 1 2 3 4 5 6 7 8 9 10 11
before swap j i
before swap j i
after swap i j
f'j
• Claim. Swapping two adjacent, inverted jobs reduces the number of inversions by
one and does not increase the max lateness.
• Pf. Let be the lateness before the swap, and let ' be it afterwards.
– 'k = k for all k i, j j f j d j (definition)
– 'i i fi d j ( j finishes at time f i )
– If ’ >0, then
i
fi di (di dj )
i (definition)
Page 17
• Theorem: The greedy is optimal.
Pf: Let G be the solution generated by the greedy
algorithm. Let Opt be an optimal solution.
If there is an adjacent inversion in Opt. We can
swap it. After swapping, the no. of inversion is
reduced and the total lateness is not increased.
After a number of swapping, Opt =G.