Unit-4-Spanning Tree
Unit-4-Spanning Tree
undirected graph that includes all the vertices of the graph. Or, to
say in Layman’s words, it is a subset of the edges of the graph that
forms a tree (acyclic) where every node of the graph is a part of the
tree.
The minimum spanning tree has all the properties of a spanning tree
with an added constraint of having the minimum possible weights
among all possible spanning trees. Like a spanning tree, there can
also be many possible MSTs for a graph.
1 7 6
2 8 2
2 6 5
Weight Source Destination
4 0 1
4 2 5
6 8 6
7 2 3
7 7 8
8 0 7
8 1 2
9 3 4
10 5 4
11 1 7
14 3 5
Now pick all edges one by one from the sorted list of edges
Step 1: Pick edge 7-6. No cycle is formed, include it.
Add edge 7-6 in the MST
Step 6: Pick edge 8-6. Since including this edge results in the cycle,
discard it. Pick edge 2-3: No cycle is formed, include it.
Step 7: Pick edge 7-8. Since including this edge results in the cycle,
discard it. Pick edge 0-7. No cycle is formed, include it.
Add edge 0-7 in MST
Step 8: Pick edge 1-2. Since including this edge results in the cycle,
discard it. Pick edge 3-4. No cycle is formed, include it.
Add edge 3-4 in the MST
Step 1 - First, we have to choose a vertex from the above graph. Let's
choose B.
Step 2 - Now, we have to choose and add the shortest edge from vertex B.
There are two edges from vertex B that are B to C with weight 10 and edge
B to D with weight 4. Among the edges, the edge BD has the minimum
weight. So, add it to the MST.
Step 3 - Now, again, choose the edge with the minimum weight among all
the other edges. In this case, the edges DE and CD are such edges. Add
them to MST and explore the adjacent of C, i.e., E and A. So, select the edge
DE and add it to the MST.
Step 4 - Now, select the edge CD, and add it to the MST.
Step 5 - Now, choose the edge CA. Here, we cannot select the edge CE as it
would create a cycle to the graph. So, choose the edge CA and add it to the
MST.
So, the graph produced in step 5 is the minimum spanning tree of the
given graph. The cost of the MST is given below -
Algorithm
1. Step 1: Select a starting vertex
2. Step 2: Repeat Steps 3 and 4 until there are fringe vertices
3. Step 3: Select an edge 'e' connecting the tree vertex and fringe vertex that
has minimum weight
4. Step 4: Add the selected edge and the vertex to the minimum spanning tre
eT
5. [END OF LOOP]
6. Step 5: EXIT