Question

Let G = (V, E) be a weighted, connected and undirected graph. Describe an efficient algorithm that decides whether there are exactly 2 different MSTs in G.

The previous question which I already solved was a lot easier: Describe an efficient algorithm that decides whether there is exactly one MST in G.

This is how I solved the latter question:

We run Kruskal algorithm and then color the edges of the new MST in blue and the rest of the edges in red.

Then I used another simple algorithm that we've seen (that uses Kruskal) that find a MST in a graph that contains a maximum number of red edges - which means that it's a MST in the graph G regardless of the edges' color, and every other MST cannot contain more red edges then the MST the algorithm finds.

Now there is exactly one MST iff the algorithm found the same MST (that contains all the blue edges).

The other question here seems a lot more complicated. I've tried using the algorithm described above and also tried to use various other tricks but neither has worked.

By the way, I've heard that there is an algorithm that counts the number of different MSTs in a graph, but it really is an overkill - and I was asked to provide a simple algorithm.

I would appreciate any help, Thanks

Was it helpful?

Solution

I might be underthinking it but your approach seems needlessly complicated. To determine if there were 2 different MSTs I would start by running Kruskal to get the first MST. Then you just run it again and see if you could avoid taking an edge from the first MST.

In each step of Kruskal, you add the cheapest edge that connects 2 previously unconnected components. So you have to sort the edges by weight and run through them, adding them to the MST if they connect 2 unconnected components. When there are multiple MSTs you will reach a point where you get to choose between 2 edges of the same weight that both connect the same components.

When you have run Kruskal once, you know which edges are in your MST. If you run it a second time, you will again sort the edges by weight and add the cheapest edges (that connect 2 unconnected components) to your graph. However, if you get the choice to add 2 edges that connect the same components then you can take the edge you didn't take the first time. The end result will then be a different MST (does not contain the one edge) but a valid MST as you operated entirely according the rules of Kruskal.

You basically just do Kruskal but change your tie breaker for edges with the same weight. Iterate the procedure to find even more different MSTs. If you want to know if there're only 2 MST's you should try and find a third MST.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top