简体   繁体   中英

Find if MST T is still a MST for new graph G' if a new edge is added to undirected weighted graph G

This is a review problem and I am trying to get a feel for whether my answer is right or not.

Here is the gist of the original question:

You have an MST, T, of a weighted undirected graph then a new edge is introduced in the original graph between nodes (u and v) to create a new graph G'. Give a linear time algorithm to determine if T is an MST of G'.

My answer:

The MST T of the original graph does not contain any cycles. There should be only one path from node u to node v. We can add the new edge into our MST which can be done in O(1) time to produce our new tree T'. Then, we can run DFS on T' from u to v which completes in O(|V| + |E|) time. With our new edge added, we should get at most 2 paths between u and v. One will use the new edge and one wont. We can compare these two paths in O(1) time. If the shorter of the two uses the new edge, then we know the original MST "T" is not a MST for the new graph G'. Our whole algorithm will complete in linear time.

It's a correct algorithm, and you've proved that if it finds a lighter tree, then the old tree wasn't minimum. You still need to prove that if it doesn't find a lighter tree, then the old tree is still the lightest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM