CSCE 411H Design and Analysis of Algorithms: Set 8: Greedy Algorithms Prof. Evdokia Nikolova Spring 2013
CSCE 411H Design and Analysis of Algorithms: Set 8: Greedy Algorithms Prof. Evdokia Nikolova Spring 2013
a b c d e f
f e
M1
4 M2
8
edges in
12 7 neither
Let e be edge with minimum weight that is in one MST
but not the other (e.g., orange or blue but not both)
in the example it is the edge with weight 4
WLOG, assume e is in M1 (e.g., the orange MST)
3 M1
4 5 M2
8
edges in
12 7 neither
Let e' be an edge in the cycle that is not in M1
in the example, the only possibility for e' is the edge with weight 7,
since the edges with weights 3 and 5 are in M1 (the orange MST)
By choice of e, weight of e must be > weight of e
in the example, 7 > 4
3
M3
8 4 5
edges not
12 7 in M3
Result is a new spanning tree, M3, whose weight is less
than that of M2!
a 11 i 4 e
14
7 6
8 10
h g f
1 2
Then we have
|V| inserts and one decrease-key in the
initialization: O(VTins+Tdec)
|V| iterations of while
one extract-min per iteration: O(VTex) total
4 4
5 1 5 1
s s
6 6
Prim's Dijkstra's
MST SSSP
Need to show
Ti Ti+1 path in Ti+1 from
s x u s to u is a
shortest path,
and has distance
d[u]
CSCE 411H, Spring 2013: Set 8 56
Correctness of Dijkstra's Alg
P, path in Ti+1
Ti Ti+1
s from s to u
x u
a P', another
path from s to u
b
(a,b) is first edge in P' that
leaves Ti