How to update MST after deleting an edge from the graph?

被刻印的时光 ゝ 提交于 2019-12-12 08:59:12

问题


I have a graph represented with adjacency lists and his MST represented by parent array.

My problem is that I need to delete an edge from the graph and update parent array.

I've already manage to do the cases when:

  1. the edge doesn't exist;
  2. the edge is in graph but not in MST (MST doesn't change);
  3. and the edge is the only path from two nodes(in this case I return null, because the graph is not connected).

What can I do when the edge is in MST and the edge in graph is in a cycle? I need to do this in O(n+m) complexity.

I write the costs of edges with red color.


回答1:


Just search the minimum-distance path of the now-disconnected tree portion to the rest of the tree and add that path in between-- which is a single edge.

Say your original tree is T. With the removal of the edge, it is now split into trees T1 and T2.

Take one of these-- say T2. Every edge incident to a node on T2 is either on T2 or is one connecting T2 to T1. Among these edges incident to a node on T2, pick the one which ( (has its other end at a T1 node) and (has the minimum cost among all such edges) ). Search for this edge, say e=(u,v), takes O(|E|) time. O(|N|) if the separated portion is a leaf.

if there were a tree, say T', with less cost than T1 \union T2 \union {e}, then the node sets N1 and N2 of T1 and T2 would have more inter-connections than just one edge,

i.e., there would be two or more more edges on T' that begin at a node in N1 and end at a node in N2. Otherwise, ( (T1 and T2 are minimum spanning trees resply. over N1 and N2) and (e is the least costly connection between T1 and T2) ) would be false. But then, any go-between T1 and T2 is costlier than e=(u,v)-- contradicts.

Skipped some proof details. hope this helps.



来源:https://stackoverflow.com/questions/13659191/how-to-update-mst-after-deleting-an-edge-from-the-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!