CSL 356: Analysis and Design of Algorithms: Ragesh Jaiswal CSE, IIT Delhi
CSL 356: Analysis and Design of Algorithms: Ragesh Jaiswal CSE, IIT Delhi
Algorithms
Ragesh Jaiswal
CSE, IIT Delhi
Greedy Algorithms
Smallest duration
Least overlapping
this.
Proof: Let 1, 2, , be the sequence of requests that
GreedySchedule picks and 1, 2, , be the requests in
sorted by finishing time.
Claim: (1) (1)
this.
Proof: Let 1, 2, , be the sequence of requests that
GreedySchedule picks and 1, 2, , be the requests in
sorted by finishing time.
Claim: (1) (1)
Claim: If (1) (1), (2) (2), , (1 )
(1 ), then ( ) ().
this.
Proof: Let 1, 2, , be the sequence of requests that
GreedySchedule picks and 1, 2, , be the requests in
sorted by finishing time.
Claim: (1) (1)
Claim: If (1) (1), (2) (2), , (1 )
(1 ), then ( ) ().
GreedySchedule could not have stopped after
Running time:
20
25
50
30
10
50
60
30
20
25
50
30
10
50
60
30
20
25
50
30
10
50
60
30
GreedySteal
While Sack is not full
- Choose an item from that has the largest cost per unit volume
- Put as much as you can of this item in the sack and delete from
W = 50
20
25
50
30
10
50
60
30
volume value.
Let (1, , ) be the volume of items in the sack chosen
by GreedySteal.
Let (1, , ) be some optimal volume of items that
maximizes the profit.
Claim: For all ,
1 1 + + 1 1 + +
End
Problems to think about:
1. Consider the fractional-knapsack problem. Think of an exchange
argument to prove that the greedy algorithm gives the optimal
solution.