Professional Documents
Culture Documents
Minimum Spanning Trees: Presentation For Use With The Textbook,, by M. T. Goodrich and R. Tamassia, Wiley, 2015
Minimum Spanning Trees: Presentation For Use With The Textbook,, by M. T. Goodrich and R. Tamassia, Wiley, 2015
Minimum Spanning Trees: Presentation For Use With The Textbook,, by M. T. Goodrich and R. Tamassia, Wiley, 2015
G containing edge e 7
Proof: Replacing f with e yields
Let T be an MST of G another MST
If T does not contain e, consider the
U V
cycle C formed by e with T and let f f 7
be an edge of C across the partition 4
By the cycle property,
9
weight(f) weight(e) 2 5
Thus, weight(f) = weight(e) 8
We obtain another MST by replacing 8 e 3
f with e
7
© 2015 Goodrich and Tamassia Minimum Spanning Trees 6
Prim-Jarnik’s Algorithm
Similar to Dijkstra’s algorithm
We pick an arbitrary vertex s and we grow the MST as
a cloud of vertices, starting from s
We store with each vertex v label d(v) representing
the smallest weight of an edge connecting v to a
vertex in the cloud
At each step:
We add to the cloud the vertex u outside the cloud with the
smallest distance label
We update the labels of the vertices adjacent to u
7 7
7 D D
2 2 7
B 4 B 4
5 9 9 4
2 5 F 5 5
C 2 F
8 C
3 8
8 8 3
E E
A 7 A
0 7 7 7
0
© 2015 Goodrich and Tamassia Minimum Spanning Trees 9
Example (contd.)
7
7 D
2
B 4
5 9 4
2 5 F
C
8
8 3
E
A 3 7
0 7
7 D
2
B 4
5 9 4
2 5 F
C
8
8 3
E
A 3
0 7
G G
B 8 B 8
4 4
9 E 9 E
5 6 5 6
1 F 1 F
C 11 3 C 11 3
2 2
7 D H 7 H
D
A 12 A 12
10 10
© 2015 Goodrich and Tamassia Campus Tour 14
Example (contd.)
G G
B 8 B 8
4 4
9 E 9 E
5 6 6
1 F 1 5 F
C 11 3 C 11 3
2 2
7 D H 7 H
D
A 12 A 12
10 10
five steps
s
ep
st
G o G
8 8
tw
B 4 B 4
9 E 9 E
5 6 5 6
1 F 1 F
C 11 3 C 11 3
2 2
7 D H 7 D H
A 12 A 12
10 10
© 2015 Goodrich and Tamassia Campus Tour 15
Data Structure for Kruskal’s Algorithm
The algorithm maintains a forest of trees
A priority queue extracts the edges by increasing
weight
An edge is accepted it if connects distinct trees
We need a data structure that maintains a partition,
i.e., a collection of disjoint sets, with operations:
makeSet(u): create a set consisting of u
find(u): return the set storing u
union(A, B): replace sets A and B with their union
Algorithm BaruvkaMST(G)
T V {just the vertices of G}
while T has fewer than n - 1 edges do
for each connected component C in T do
Let edge e be the smallest-weight edge from C to another
component in T
if e is not already in T then
Add edge e to T
return T
Algorithm (animated)
2 4
3 8
8 5
9 4 7 4
9
3
1 6 6 6
5
4
2 4
3
8 5
9 4 7
3
1 6 6
5
4
© 2015 Goodrich and Tamassia Minimum Spanning Trees 21