Professional Documents
Culture Documents
Greedy Algorithms: Interval Scheduling Greedy Algorithm
Greedy Algorithms: Interval Scheduling Greedy Algorithm
Greedy Algorithms
Suppose that the algorithm has selected k + 1 talks. Once we included t1, scheduling the talks so that as many as possible
First, we show that there is an optimal scheduling that contains t1 talks are scheduled is reduced to scheduling as many talks as possible
Indeed, if we have a schedule that begins with the talk ti , i > 1, that begin at or after time e1.
then this first talk can be replaced with t1 . The greedy algorithm always schedules t1 , and then schedules k talks
To see this, note that, since e1 ≤ ei, all talks scheduled after t1 still choosing them from those that start at or after e.1
can be scheduled. By the induction hypothesis, it is not possible to schedule more than k
such talks. Therefore, the optimal number of talks is k + 1.
t4
QED
t3 t7
t1 t5 t8
t2 t6
Suppose that every arc e of a digraph G has length The Single Source Shortest Path Problem
(or cost, or weight, or …) len(e) Instance:
Then we can naturally define the length of a directed path in G, Digraph G with lengths of arcs, and node s
and the distance between any two nodes Objective:
Find shortest paths from s to all nodes of G
The s-t-Shortest Path Problem
Instance:
Greedy algorithm:
Digraph G with lengths of arcs, and nodes s,t
Attempts to build an optimal solution by small steps, optimizing
Objective: locally, on each step
Find a shortest path between s and t
Method: 2 1
let S be the set of explored nodes
for each v ∈ S let d(v) be the distance from s to v a b
4
is minimal
set S:=S∪{v}, and d(v):=d’(v)
endwhile
Algorithms – Greedy Algorithms 15-13 Algorithms – Greedy Algorithms 15-14
2
c d Use the exchange argument
4
2
5 Proof
Let T be a spanning tree that does not contain e
f
We find an edge e’ in T such that replacing e’ with e we obtain
another spanning tree that has smaller weight
Algorithms – Spanning Tree 15-25 Algorithms – Spanning Tree 15-26
Let u be the first vertex on this path not in S, and let e’ = tu be the
edge connecting S and V – S.