Kruskal’s Algorithm is almost similar to Prim’s Algorithm. The difference is that in Prim’s algorithm, the root node chosen is the one having minimum weight but in Kruskal’s algorithm the root vertex is chosen randomly provided the edges are arranged in the ascending order. Here are few steps to follow in finding Minimum Spanning Tree (MST). We shall use the same example from Prim’s.
Fig 1.1 ProblemFig 1.2 Arranging in Ascending order
Step 1: Arrange the edges in ascending order as shown in Fig 1.2.
Step 2: From the given graph, remove all loops and parallel edges. The one with the maximum weight of the parallel edges should be removed. According to Fig 1.1, remove the loop around F and the parallel edge of BD that has maximum weight 8. That gives the below i.e. Fig 1.3
Fig 1.3 After removing loop and parallel edges
Step 3: Choose first node from the ascending order. So, let us choose E->F from Fig 1.3. We can choose E->D as well. That doesn’t change the final result.
Step 4: From the root node E, select the path to which the edge weight is minimum out of the remaining connected nodes to the root. Here minimum weight is 2 compared to E->C which is 3. We are free to choose E->F or E->D. We choose here E->F.
Fig 1.4 Connecting root node E to F i.e. edge with minimum weight
Step 5: Considering F as a node, apply step 3. Now we have to consider the weights of the edges from the previous vertices i.e E in this case. Since E->D edge has minimum weight i.e 2 out of 3 (E->C) and 5 (F->D), we choose E->D.
Fig. 1.5
Step 6: Repeat steps 4 and 5 until all the vertices are connected according to the ascending order.
5 thoughts on “Kruskal’s Algorithm”