Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update minimum spanning tree if edge is added

I have a possible solution for the following question, but not sure if correct:

Assume we have already found a minimum spanning tree T for a weighted, undirected graph G = (V,E). We would like to be able to efficiently update T should G be altered slightly.

An edge is added to G to produce a new graph. Give an algorithm that uses T to find a minimum spanning tree for the new graph in O(|V|) time.

My algorithm:

for each vertex do
   if smallest edge not in T then
      replace this edge with existing edge in T
      break
   end if
end for

I do not have much experience in writing pseudocode, so my algorithm might be over-simplified or incorrect. Please correct me if I am wrong. Thanks!

like image 488
James the Great Avatar asked Jun 17 '15 02:06

James the Great


People also ask

How do you update MST after deleting the edge of the graph?

mst = 1 or 0 . After deleting an MST edge, search outward along the MST from each vertex, marking each vertex as part of the 'left' or 'right' halves of the split MST. This takes O(E) each side. Then for all edges (u, v) if u and v are in different MST halves, keep the smallest such edge and add it to the MST.

Does adding an edge to a spanning tree create a cycle?

We will prove that adding an edge to it creates a cycle. Since G is a tree, any 2 vertices have a unique simple path between them. Therefore, if an edge is added between 2 vertices, those vertices will now have multiple paths between them.

How do I add edges in minimum spanning tree?

Let G=(V,E) undirected connected graph, w:E→R weight function. Let T a MST (minimum spanning tree) of G. Now, we add a new edge e′ to E with weight w(e′). Find an algorithm that updates T so it will be a MST of the new graph G′=(V,E∪{e′}).


1 Answers

Don't know if your algorithm is correct, but it doesn't seem O(|V|) at least, because getting the "smallest edge not in T" of a vertex cannot be done in O(1).

The most usual way to add an edge e=(u, v) into a MST T is:

  • Run a BFS in T from u to v to detect the edge with maximum value in that path. (O(|V|))
  • If that edge's weight is greater than the weight of the edge you're trying to add, remove that old edge and add the new one. Otherwise, do nothing, because the new edge would not improve the MST. (O(1)).

The rationale behind this solution is that simply adding the edge into T would create exactly one cycle, and to restore the MST property you have to remove the edge with maximum value from that cycle.

like image 159
Juan Lopes Avatar answered Nov 08 '22 02:11

Juan Lopes