gpt4 book ai didi

algorithm - 克鲁斯卡尔的 MST : Union operation using Union-Find DS: Guarantee on join taking place between the nodes with least edge weight

转载 作者:行者123 更新时间:2023-12-04 07:43:07 24 4
gpt4 key购买 nike

在最小生成树中,我们需要在移动到其他边之前以最小的权重连接边。为了执行连接,我们使用 UF DS 的联合操作,它连接不相交数据集的代表元素。是否可以保证代表性元素将是我们打算加入的具有最小边权重的节点?如果我认为这是正确的,则连接很可能发生在要连接的组件的其他节点上。
谢谢

最佳答案

不,没有这样的保证。幸运的是,Kruskal's 使用了disjoint-set 数据结构来保持到目前为止扫描的边缘的连通性,并且代表对于这个目的并不重要。如果你最终想要树结构,你需要做一些不同的事情(边集上的 DFS,为不相交集数据结构划分一个动态树,以便你可以加入实际的端点,改用 Prim 的)。

关于algorithm - 克鲁斯卡尔的 MST : Union operation using Union-Find DS: Guarantee on join taking place between the nodes with least edge weight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67346889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com