Professional Documents
Culture Documents
Chapter-6
Objectives
To Study Spanning Tree To Study Minimal Spanning Tree To Study Algorithm for construction of Minimal Spanning Tree Kruskals Algorithm Prims Algorithm
Modeling the Problem The graph is a complete, undirected graph G = ( V, E ,W ), where V is the set of pins, E is the set of all possible interconnections between the pairs of pins and w(e) is the length of the wire needed to connect the pair of vertices. Find a minimum spanning tree.
Spanning Tree
A spanning tree is a sub graph of a graph. It is a tree containing all the nodes of the graph. If we append any edge into the spanning tree, then a cycle is formed.
Spanning trees
Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges do not have an associated direction ...then a spanning tree of the graph is a connected subgraph in which there are no cycles
Spanning Tree
Minimizing costs
Suppose you want to supply a set of houses (say, in a new subdivision) with:
electric power water sewage lines telephone lines
To keep costs down, you could connect these houses with a spanning tree (of, for example, power lines)
However, the houses are not all equal distances apart
To reduce costs even further, you could connect the houses with a minimum-cost spanning tree
B
5
16 11
B
5
33
F
18
14
C
10
F
E
18
Kruskals Algorithm
To find the minimal spanning tree Step 1: Lengths of the graph are arranged in ascending order
Step 9: Edges (1, 2), (4, 5), (4, 6) & (5, 7) forms cycle. So they are rejected
Prims Algorithm
To find the Minimal Spanning Tree
Step 2: We have to include the edges whose one vertex is already in the tree And other vertex is new. So we can include (1, 3), (2, 3), (2, 5), (4, 5), (5, 6) or (5, 7)
Step 4: Now, we can insert (1, 4), (1, 2), (2, 3), (2, 5), (4, 5), (5, 6) or (5, 7)
Step 8: Next insert edge (6, 7) This is the Final Minimal Spanning Tree
Prims algorithm
1
10 6 25 24 5 18 22 12
28
2 14 7 16 3 10
1
2
6
5
Prims algorithm
1
10 6 25 24 5 18 22 12
28
2 14 7 16 3 10
1
2
6
25 5
Prims algorithm
1
10 6 25 24 5 18 22 12
28
2 14 7 16 3 10
1
2
6
25 5
22
4
Prims algorithm
1
10 6 25 24 5 18 22 12
28
2 14 7 16 3 10
1
2
6
25 5
3
12 4
22
Prims algorithm
1
10 6 25 24 5 18 22 12
28
2 14 7 16 3 10
1
2 16
6
25 5
3
12 4
22
Prims algorithm
1
10 6 25 24 5 18 22 12
28
2 14 7 16 3 10
1
2 14 16
6
25 5
3
12 4
22
Cost = 99
Kruskals Algorithm
5
A
1 B 8 9
E 2
7 D 5 F
{A,B}
1 2 5 5 7 8 9 12
12
C
A B C
E D F
Kruskals Algorithm
{A,B} {A,D}
A 1 B C F E D
1 2 5 5 7 8 9 12
{A,E}
Kruskals Algorithm
{A,B} {A,D}
A 1 B C F E 2
1 2 5 5 7 8 9 12
{A,E}
D
Kruskals Algorithm
{A,B} {A,D}
5 A 1 B C F E 2
1 2 5 5 7 8 9 12
{A,E}
D
Kruskals Algorithm
{A,B} {A,D}
5 A 1 B C E 2
1 2 5 5 7 8 9 12
{A,E}
D 5 F
Kruskals Algorithm
{A,B} {A,D}
5 A 1 B C E 2
1 2 5 5 7 8 9 12
{A,E}
D 5 F
Kruskals Algorithm
{A,B} {A,D}
5 A 1 B E 2
1 2 5 5 7 8 9 12
{A,E}
D 5 F
Kruskals Algorithm
{A,B} {A,D}
5 A 1 B E 2
1 2 5 5 7 8 9 12
{A,E}
D 5 F
Kruskals Algorithm
{A,B} {A,D}
5 A 1 B E 2
1 2 5 5 7 8 9 12
{A,E}
D 5 F