15

I'm trying to find an efficient method of detecting whether a given graph G has two different minimal spanning trees. I'm also trying to find a method to check whether it has 3 different minimal spanning trees. The naive solution that I've though about is running Kruskal's algorithm once and finding the total weight of the minimal spanning tree. Later , removing an edge from the graph and running Kruskal's algorithm again and checking if the weight of the new tree is the weight of the original minimal spanning tree , and so for each edge in the graph. The runtime is O(|V||E|log|V|) which is not good at all, and I think there's a better way to do it.

Any suggestion would be helpful, thanks in advance

Raphael
  • 73,212
  • 30
  • 182
  • 400
itamar
  • 293
  • 1
  • 3
  • 6

4 Answers4

7

Kapoor & Ramesh (proper SIAM J. Comput. version, free(?) personal website version) give an algorithm for enumerating all minimum spanning trees in both weighted and unweighted graphs.

My understanding of the basic idea is that you start with one MST, then swap edges that lie along cycles in the graph (so as long as the weights are okay, you're replacing one edge with another that you know will reconnect the tree).

For the weighted case they give a running time to list all minimum spanning trees of $O(N\cdot|V|)$ where $N$ is the number of such spanning trees. It enumerates them in order of increasing weight, and my current (cursory) understanding suggests that it's perfectly feasible to terminate the algorithm after it has generated a given number of trees (as it just starts with the MST and produces them sequentially).

Luke Mathieson
  • 18,373
  • 4
  • 60
  • 87
2

One can show that Kruskal's algorithm can find every minimal spanning tree; see here.

Therefore, you can execute Kruskal and whenever you have multiple edges to choose from, branch. Once you have branched $k$ times, you know that there are at least $k$ different minimal spanning trees. Unfortunately, multiple branches may result in the same tree by adding edges of same weight in different orders, so this does not help much without further work/insight.

Raphael
  • 73,212
  • 30
  • 182
  • 400
1

To see if there is more than one MST, consider e.g. Kruskal's algorithm. The only way it could construct different MSTs is by leaving out edges by choosing another one when there are several with the same weight. But those same-weight edges might have been ruled out because they formed a cycle with lighter edges...

So you should run Kruskal's algorithm, and when there are several edges with the same weight to consider, add all of them that can be added without creating cycles. If there is an edge of this weight left over, and it doesn't close a cycle with any of the edges with lower weights (which were added before), there is more than one MST. Checking if there are exactly 2 or 3 or more, etc looks much harder...

vonbrand
  • 14,204
  • 3
  • 42
  • 52
0

Modidying Kruskal's algorithm: While ordering the edges, cluster edges with equal weight. Now, at the point where you process the edges in order, each time you reach a new cluster, first check all edges separately and remove from the cluster those that would close a cycle, given what was built before the cluster. Then run all the remaining edges in the cluster now trying to add them to the MST. If any of them closes a cycle, then that was necessarily because of other edges of the same cluster inserted before, meaning that you have more than one MST.

That solution preserves the complexity of Kruskal's algorithm, only it increases the time for each edge processed.

David Richerby
  • 82,470
  • 26
  • 145
  • 239