How to organize a MST when one node disappear?
I'm doing my research and stuck with a question:
I am having a minimum开发者_Go百科 spanning tree (prim algorithm), now one node in my tree gets deleted, I wonder if there is a way i can re-organize my tree such that the optimality still maintains?
I'm looking for some suggestions here and I will appreciate your help.
Thank you!
This problem has been well-studied. Research done in 2001 found a way to maintain a graph data structure so that you can insert or remove an edge and update the minimum spanning tree in time O(log4 n), which to the best of my knowledge is the best time bound anyone has been able to come up with so far. The paper describing this algorithm is dense and tricky, but if you're interested you can find it here:
Poly-Logarithmic Deterministic Fully-Dynamic Algorithms for Connectivity, Minimum Spanning Tree, 2-Edge, and Biconnectivity
Hope this helps!
When you remove a node in the tree, it may divide the graph into more than one disconnected component. In the worst case, imagine an MST where all the edges go from one central node to all the others - like a star. In this event, if the central node is removed, the whole MST will have to be redone. So, I guess the short answer is - it depends on what node is removed. The solution is to do it like aix mentioned - find all the components which are disconnected because of the removed node and connect them greedily. This could stretch from 0 (if a leaf node is removed) to n-1 (if the center of a star is removed)
If the deleted vertex was a leaf of the MST, you don't need to do anything: you still have a spanning tree and it's still optimal.
If it wasn't a leaf, you now have two sub-trees. All you need to do is reconnect them by the shortest edge that exists between the two sub-trees. The best way to find that edge is probably by using whatever data structure you used for the Prim's algorithm (or, trivially, in O(n^2) by considering all pairs of vertices).
精彩评论