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

纵饮孤独 提交于 2020-01-25 10:01:06

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/55210491/finding-the-minimum-spanning-tree-of-a-graph-using-kruskals-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!