1
170
More about implementation
Only
V1
edges were used, the rest  wasted.
Idea:
»
keep
nodes
in the heap, instead of edges.
»
Key:
distance
of node
from A
over a single edge.
»
Initially:
key(v) = infinity
, for all v.
key(root) = 0
.
So why does this work ???
x
root
vvx E
key v
key v w vx
xx
A
Repeat:
do:
Pick smallestkey , add
to
.
:
() m
in
(
()
, ( )
)
Lecture 14, Nov 11 2010
171
Alternative Implementations
Total:
O(E)
decreasekey,
O(V)
extractmin.
extract min
decrease key
Total
array
( )
heap
Fib. heap
OV
O
O
EV
O
O
VV
E
(
)
(log )
(log )
(
log )
(log )
( )
( log
)
1
2
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
172
Kruskal’s Algorithm
Main loop:
»
Scan edges in increasing order of weight
»
Add current edge to output if no loop created.
Why does this result in
MST
??
»
Observation: minweight edge is always in
MST
»
Proof: Assume there exists a tree without this edge.
Add
this edge to the tree  this
creates a cycle
.
Delete maxweight edge on this cycle, we get a lighter tree !
This is the end of the preview. Sign up
to
access the rest of the document.
 '09
 Algorithms, Graph Theory, Array data structure, Disjointset data structure, Kruskal

Click to edit the document details