Topics: Minimum Spanning Trees
Topics: Minimum Spanning Trees
Topics
Minimum Spanning Trees
1.1
1.2
5
6
A connected,
undirected Graph
2
4
4
1
1
Many possible Spanning tree
1.3
5
6
1
2
3
1
Minimum Spanning tree
Data Structure and Algorithm
1.4
A weighted Graph
Some Definition
A cut ( S, V-S ) of an undirected graph G =(V,E) is a partition of V.
An edge (u,v) crosses the cut ( S, V-S ) if one of its endpoints is in S
S
V-S
Data Structure and Algorithm
1.5
Generic MST
Generic_MST(G,w)
A=0
//empty set
while A does not form a spanning tree
do
1.6
Kruskals Algorithm
This is a greedy algorithm. A greedy algorithm
Take a graph with 'n' vertices, keep adding the shortest (least
cost. The order in which the edges are chosen, in this case,
does not matter. Different MSTs may result, but they will all
have the same total cost, which will always be the minimum
cost
1.7
8
4
2
11
10
2
14
1.8
8
4
2
11
10
2
14
1.9
8
4
2
11
10
2
14
1.10
8
4
2
11
10
2
14
1.11
8
4
2
11
10
2
14
1.12
8
4
2
11
10
2
14
1.13
8
4
2
11
10
2
14
1.14
8
4
2
11
10
2
14
1.15
8
4
2
11
10
2
14
1.16
8
4
2
11
10
2
14
1.17
8
4
2
11
10
2
14
1.18
8
4
2
11
10
2
14
1.19
8
4
2
11
10
2
14
1.20
8
4
2
11
10
2
14
1.21
Kruskals Algorithm
MST_KRUSKAL ( G, w )
A=0
//empty set
for each vertex of V[G] do
Make_Set(v)
Sort the edges of E by nondecreasing weight w
for each edge (u,v) of E, in order by nondecreasing
weight do
if Find_Set(u) <> Find_Set(v) then
A = A U {(u,v)}
Union (u,v)
return A
Data Structure and Algorithm
1.22
Prims Algorithm
This algorithm builds the MST one vertex at a time. It starts
1.23
8
4
2
11
10
2
14
1.24
8
4
2
11
10
2
14
1.25
8
4
2
11
10
2
14
1.26
8
4
2
11
10
2
14
1.27
8
4
2
11
10
2
14
1.28
8
4
2
11
10
2
14
1.29
8
4
2
11
10
2
14
1.30
8
4
2
11
10
2
14
1.31
8
4
2
11
10
2
14
1.32
Prims Algorithm
MST_PRIM (G,w,r)
Q = V[G]
// r = starting node
//priority queue containing vertex
for each u of Q do
key[u] = infinite
key[r] = 0
pre[r] = NIL
//pre = parent
while Q is not empty do
u = ExtractMin(Q)
for each v of Adj[u] do
1.33