algorithmdata-structuresgraphkruskals-algorithmprims-algorithm

Finding the minimum spanning tree of a graph using Kruskal's Algorithm


Here is a Graph where I need to find the minimum spanning tree of G using Prim's and Kruskal's algorithms.

I found the minimum spanning tree using Prim's algorithm. Here is my attempt.

I am having difficulty in finding the minimum spanning tree using Kruskal's algorithm. I have seen many videos related to Kruskal's graph algorithm but I ended up getting the same graph as Prim's algorithm.

Can anyone please show me how to find the minimum spanning tree of the graph using Kruskal's algorithm?


Solution

  • Prims and Kruskals will always give you the same answer if all the edges of the graph have distinct weights, as there is only a single min-spanning tree that exists. For graph having many edges with same weights, the algorithms could give you a different answer but not always. Depends on the way the nodes are explored in the implementation. This graph can have many different min-spanning trees.

    As your graph has all distinct edge weights, you will always get the same answer.