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?
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:
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.
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.
© 2022 - 2024 — McMap. All rights reserved.