Explain the Kruskal's shortest spanning tree algorithm with a suitable example by taking a graph with 7 vertices, 15 edges and with suitable weights for each edge.
Algorithm
Step 1:
Kruskal's algorithm is the shortest spanning tree algorithm that finds an edge with the least possible weight to connect any two trees in the connected undirected graph. It is also called the greedy algorithm. Graph with 7 vertices and 15 weighted edges is
Step 2 :
List all vertices and their adjusting edge and sort all the edges in the increasing order of their weights. The graph contains 7 vertices(A,B,C,D,E,F and G) and 15 weighted edges. The shortest-spanning-tree will be having (total vertices-1).
=6 edges
sort all the edges in the increasing order of their weight
Weight |
Source |
Destination |
3 |
A |
C |
3 |
B |
C |
3 |
D |
E |
3 |
E |
G |
4 |
A |
B |
4 |
C |
E |
4 |
D |
F |
5 |
B |
D |
5 |
D |
G |
5 |
F |
G |
6 |
A |
D |
6 |
C |
D |
6 |
E |
F |
7 |
B |
G |
8 |
A |
E |
Step 3:
pick the smallest edge check if the edge creates a cycle or loop discard it. If the cycle or loop is not formed then
include the edge to form the spanning tree.
Pick edge A-C. No cycle is formed, include it to create a shortest-
Spanning-Tree:
Pick edge B-C. No cycle is formed, so include it to create a
Step by step
Solved in 5 steps with 5 images