使用 Kruskal 算法查找图的最小生成树

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

Here is a Graph 我需要使用 Prim 的Kruskal 的 算法找到 G 的最小生成树。

我用Prim算法找到了最小生成树。 Here is my attempt.

我在使用 Kruskal 算法找到最小生成树时遇到困难。我看过很多与 Kruskal 的图算法相关的视频,但我最终得到的图与 Prim 的算法相同。

任何人都可以告诉我如何使用 Kruskal 算法找到图的最小生成树吗?

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.

由于您的图形具有所有不同的边权重,因此您将始终得到相同的答案。

Prim 和 Kruskal 的算法都找到最小生成树。因为您给出的图具有彼此不同的边权重,所以不会有不同的生成树都是 minimum.as 只要正确实现了两种算法,它们就会找到同一棵树。这意味着 MST 之间不能有任何变化。