Prim 的 MST:起始节点重要吗?
我直观地感觉到,如果使用 Prim 算法来查找图的最小生成树,那么选择哪个根节点并不重要 - 无论如何,生成的 MST 将具有相同的权重。这是正确的吗?
I intuitively feel that if one is using Prim's algorithm to find a graph's minimum spanning tree, it doesn't matter which root node is picked - the resultant MST will have the same weight regardless. Is this correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是正确的。选择不同的起始节点可能会产生不同的生成树,但它始终具有相同的权重:尽可能小的权重。
That is correct. Choosing a different starting node could give you a different spanning tree, but it will always have the same weight: the minimal possible.
这是因为最小值的唯一性。
证明:
This is because of uniqueness of minima.
Proof:
无论起始节点/顶点如何,树的权重/成本都将相同;然而,树的形状可能不同。当候选资格的两条边具有相同的权重且最终成为当前最小值时,选择取决于实现。除非存在真正的打破平局的步骤(这不太可能;在具有许多等权边的图中,这可能需要 O(n),没有真正的增益),否则它很可能是“首先找到”。这意味着添加和访问节点/顶点的顺序对于打破平局很重要,因此起始节点/顶点可以影响形状。
其次,它可能会影响性能,但这很难控制。随着堆操作随着其大小而变得更加昂贵,您需要添加尽可能少的边缘,尤其是在早期。人们可以以此作为优先考虑低度顶点的基本原理。然而,除了第一个节点/顶点之外,这不太重要。
TL;DR:对于总成本/重量:否。对于形状:是,如果有多个 MST。
The weight / cost of the Tree will be the same regardless of starting node/vertex; however, the shape of the tree may differ. When two edges up for candidacy have the same weight that ends up being the current minimum, the choice depends on the implementation. Unless there's a true tie-breaking step (which is unlikely; in graphs with many equal-weight edges this could take up to O(n), for no real gain), it is most likely "first found". This means the order in which nodes/verteces are added and visited matters for the tie-breaking and thus the starting node/vertex can affect the shape.
Secondly, it could affect performance, but this is hard to control. As heap operations become more expensive with their size, you'd want to add as few edge as possible, especially early on. One could use this as a rationale to give priority to low-degree verteces. However, this is unlikely to matter much beyond the first node/vertex.
TL;DR: For the total Cost/Weight: No. For the shape: Yes, if there are multiple MSTs.