Prim 的 MST:起始节点重要吗?

发布于 2024-08-12 04:58:56 字数 83 浏览 5 评论 0原文

我直观地感觉到,如果使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷离° 2024-08-19 04:58:56

这是正确的。选择不同的起始节点可能会产生不同的生成树,但它始终具有相同的权重:尽可能小的权重。

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.

一抹苦笑 2024-08-19 04:58:56

这是因为最小值的唯一性

证明:

Suppose there are 2 "different" minimum weights W1 and W2

W1 is minimum 
W2 is minimum
W1 != W2

This leads to contradiction because 
if W1 != W2 then 
   W1 < W2  -> W1 is minima
   or 
   W1 > W2  -> W2 is minima
Hence if W1 must equal W2.

This is because of uniqueness of minima.

Proof:

Suppose there are 2 "different" minimum weights W1 and W2

W1 is minimum 
W2 is minimum
W1 != W2

This leads to contradiction because 
if W1 != W2 then 
   W1 < W2  -> W1 is minima
   or 
   W1 > W2  -> W2 is minima
Hence if W1 must equal W2.
病女 2024-08-19 04:58:56

无论起始节点/顶点如何,树的权重/成本都将相同;然而,树的形状可能不同。当候选资格的两条边具有相同的权重且最终成为当前最小值时,选择取决于实现。除非存在真正的打破平局的步骤(这不太可能;在具有许多等权边的图中,这可能需要 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文