最小生成树算法 - 克鲁斯卡尔算法伪代码
作者:野牛程序员:2023-05-27 14:28:49其他阅读 2685
最小生成树算法 - 克鲁斯卡尔算法(Kruskal's Algorithm):
function kruskal(graph): edges = graph.getEdges() edges.sort() // 根据权重排序边 result = [] disjointSet = new DisjointSet() for node in graph.getNodes(): disjointSet.makeSet(node) for edge in edges: u = edge.start v = edge.end if disjointSet.find(u) != disjointSet.find(v): result.append(edge) disjointSet.union(u, v) return result
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892