Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Second min cost spanning tree

I'm writing an algorithm for finding the second min cost spanning tree. my idea was as follows:

  1. Use kruskals to find lowest MST.
  2. Delete the lowest cost edge of the MST.
  3. Run kruskals again on the entire graph.
  4. return the new MST.

My question is: Will this work? Is there a better way perhaps to do this?

like image 734
Evil Avatar asked Apr 22 '10 16:04

Evil


People also ask

How do you calculate the cost of minimum spanning tree?

The cost of the spanning tree is the sum of the weights of all the edges in the tree. There can be many spanning trees. Minimum spanning tree is the spanning tree where the cost is minimum among all the spanning trees.

How do you find the second minimum spanning tree using Prim's algorithm?

Sort the edges in O ( E log ⁡ , then find a MST using Kruskal in . For each edge not already in the MST, temporarily add it to the MST, creating a cycle. Find the edge with maximal weight in the cycle that is not equal to . Remove temporarily, creating a new spanning tree.

Can there be two minimum spanning trees?

Can a graph have more than one minimum spanning tree? Yes, but this is only possible if there is (1) more than one spanning tree and (2) duplicate edge weights. For a spanning tree to be a minimum spanning tree, it must have the minimum total weight.

What is minimum cost spanning tree in algorithm?

A Minimum Spanning Tree (MST) is a subset of edges of a connected weighted undirected graph that connects all the vertices together with the minimum possible total edge weight. To derive an MST, Prim's algorithm or Kruskal's algorithm can be used.


1 Answers

You can do this -- try removing the edges of the MST, one at a time from the graph, and run the MST, taking the min from it. So this is similar to yours, except for iterative:

  1. Use Kruskals to find MST.
  2. For each edge in MST:
    1. Remove edge from graph
    2. Calculate MST' on MST
    3. Keep track of smallest MST
    4. Add edge back to graph
  3. Return the smallest MST.
like image 192
Larry Avatar answered Oct 11 '22 23:10

Larry