Skip to main content
Commonmark migration
Source Link

A previous answer indicates an algorithm to determine whether there are multiple MSTs, which, for each edge $e$ not in $G$, find the cycle created by adding $e$ to a precomputed MST and check if $e$ is not the unique heaviest edge in that cycle. That algorithm is likely to run in $O(|E||V|)$ time.

A simpler algorithm to determine whether there are multiple MSTs of G in $O(|E|\log(|V|))$ time-complexity.

$\ $1. Run Kruskal's algorithm on $G$ to find an MST $m$.

 

$\ $2. Try running Kruskal's algorithm on $G$ again. In this run, whenever we have a choice among edges of equal weights, we will first try the edges not in $m$, after which we will try the edges in $m$. Whenever we have found an edge not in $m$ connects two different trees, we claim that there are multiple MSTs, terminating the algorithm.

 

$\ $3. If we have reached here, then we claim that $G$ has a unique MST.

An ordinary run of Kruskal's algorithm takes $O(|E|\log(|V|))$ time. The extra selection of edges not in $m$ can be done in $O(|E|)$ time. So the algorithm achieves $O(|E|\log(|V|))$ time-complexity.

Why can this algorithm determine if there are multiple MSTs?

Suppose we have an MST $m'$ that is not the same as $m$. It is enough to show that the algorithm running on $G$ will not reach step 3, since the edge found at the end of step 2, which is not in $m$ and connecting two different trees would have been included in the resulting MST had we run Kruskal's algorithm to completion. Let $w$ be the largest weight such that for any edge weighing less than $w$, it is in $m$ if and only if it is in $m'$. Because $m$ and $m'$ have the same number of edges of weight $w$, there exist edges of weight $w$ that are in $m'$ but not in $m$. If the algorithm has exited before processing edges of those edges, we are done. Otherwise, suppose the algorithm is going to process the first edge $e'$ among those edges now. Let $S$ be the set of all edges that have been preserved so far to be included in the resulting MST. $S\subset m$. Since the algorithm have not finished processing edge of weight $w$ not in $m$ such as $e'$, it must have not begun processing edges of weight $w$ in $m$. So edges in $S$ weigh less than $w$. That means $S\subset m'.$ Recall that $e'$ is in $m'$. Since $\{e'\}\cup S\subset m'$, where $m'$ is a tree, $e'$ must connect two different trees in $S$ and the algorithm exits at this point.

Note on further development
Step 1 and step 2 can be interleaved so that we can terminate the algorithm as soon as possible without processing of edges of greater weights.
In case you want to compute the number of MSTs, you may check an answer to how to compute the number of MSTs.

A previous answer indicates an algorithm to determine whether there are multiple MSTs, which, for each edge $e$ not in $G$, find the cycle created by adding $e$ to a precomputed MST and check if $e$ is not the unique heaviest edge in that cycle. That algorithm is likely to run in $O(|E||V|)$ time.

A simpler algorithm to determine whether there are multiple MSTs of G in $O(|E|\log(|V|))$ time-complexity.

$\ $1. Run Kruskal's algorithm on $G$ to find an MST $m$.

 

$\ $2. Try running Kruskal's algorithm on $G$ again. In this run, whenever we have a choice among edges of equal weights, we will first try the edges not in $m$, after which we will try the edges in $m$. Whenever we have found an edge not in $m$ connects two different trees, we claim that there are multiple MSTs, terminating the algorithm.

 

$\ $3. If we have reached here, then we claim that $G$ has a unique MST.

An ordinary run of Kruskal's algorithm takes $O(|E|\log(|V|))$ time. The extra selection of edges not in $m$ can be done in $O(|E|)$ time. So the algorithm achieves $O(|E|\log(|V|))$ time-complexity.

Why can this algorithm determine if there are multiple MSTs?

Suppose we have an MST $m'$ that is not the same as $m$. It is enough to show that the algorithm running on $G$ will not reach step 3, since the edge found at the end of step 2, which is not in $m$ and connecting two different trees would have been included in the resulting MST had we run Kruskal's algorithm to completion. Let $w$ be the largest weight such that for any edge weighing less than $w$, it is in $m$ if and only if it is in $m'$. Because $m$ and $m'$ have the same number of edges of weight $w$, there exist edges of weight $w$ that are in $m'$ but not in $m$. If the algorithm has exited before processing edges of those edges, we are done. Otherwise, suppose the algorithm is going to process the first edge $e'$ among those edges now. Let $S$ be the set of all edges that have been preserved so far to be included in the resulting MST. $S\subset m$. Since the algorithm have not finished processing edge of weight $w$ not in $m$ such as $e'$, it must have not begun processing edges of weight $w$ in $m$. So edges in $S$ weigh less than $w$. That means $S\subset m'.$ Recall that $e'$ is in $m'$. Since $\{e'\}\cup S\subset m'$, where $m'$ is a tree, $e'$ must connect two different trees in $S$ and the algorithm exits at this point.

Note on further development
Step 1 and step 2 can be interleaved so that we can terminate the algorithm as soon as possible without processing of edges of greater weights.
In case you want to compute the number of MSTs, you may check an answer to how to compute the number of MSTs.

A previous answer indicates an algorithm to determine whether there are multiple MSTs, which, for each edge $e$ not in $G$, find the cycle created by adding $e$ to a precomputed MST and check if $e$ is not the unique heaviest edge in that cycle. That algorithm is likely to run in $O(|E||V|)$ time.

A simpler algorithm to determine whether there are multiple MSTs of G in $O(|E|\log(|V|))$ time-complexity.

$\ $1. Run Kruskal's algorithm on $G$ to find an MST $m$.

$\ $2. Try running Kruskal's algorithm on $G$ again. In this run, whenever we have a choice among edges of equal weights, we will first try the edges not in $m$, after which we will try the edges in $m$. Whenever we have found an edge not in $m$ connects two different trees, we claim that there are multiple MSTs, terminating the algorithm.

$\ $3. If we have reached here, then we claim that $G$ has a unique MST.

An ordinary run of Kruskal's algorithm takes $O(|E|\log(|V|))$ time. The extra selection of edges not in $m$ can be done in $O(|E|)$ time. So the algorithm achieves $O(|E|\log(|V|))$ time-complexity.

Why can this algorithm determine if there are multiple MSTs?

Suppose we have an MST $m'$ that is not the same as $m$. It is enough to show that the algorithm running on $G$ will not reach step 3, since the edge found at the end of step 2, which is not in $m$ and connecting two different trees would have been included in the resulting MST had we run Kruskal's algorithm to completion. Let $w$ be the largest weight such that for any edge weighing less than $w$, it is in $m$ if and only if it is in $m'$. Because $m$ and $m'$ have the same number of edges of weight $w$, there exist edges of weight $w$ that are in $m'$ but not in $m$. If the algorithm has exited before processing edges of those edges, we are done. Otherwise, suppose the algorithm is going to process the first edge $e'$ among those edges now. Let $S$ be the set of all edges that have been preserved so far to be included in the resulting MST. $S\subset m$. Since the algorithm have not finished processing edge of weight $w$ not in $m$ such as $e'$, it must have not begun processing edges of weight $w$ in $m$. So edges in $S$ weigh less than $w$. That means $S\subset m'.$ Recall that $e'$ is in $m'$. Since $\{e'\}\cup S\subset m'$, where $m'$ is a tree, $e'$ must connect two different trees in $S$ and the algorithm exits at this point.

Note on further development
Step 1 and step 2 can be interleaved so that we can terminate the algorithm as soon as possible without processing of edges of greater weights.
In case you want to compute the number of MSTs, you may check an answer to how to compute the number of MSTs.

Source Link

A previous answer indicates an algorithm to determine whether there are multiple MSTs, which, for each edge $e$ not in $G$, find the cycle created by adding $e$ to a precomputed MST and check if $e$ is not the unique heaviest edge in that cycle. That algorithm is likely to run in $O(|E||V|)$ time.

A simpler algorithm to determine whether there are multiple MSTs of G in $O(|E|\log(|V|))$ time-complexity.

$\ $1. Run Kruskal's algorithm on $G$ to find an MST $m$.

$\ $2. Try running Kruskal's algorithm on $G$ again. In this run, whenever we have a choice among edges of equal weights, we will first try the edges not in $m$, after which we will try the edges in $m$. Whenever we have found an edge not in $m$ connects two different trees, we claim that there are multiple MSTs, terminating the algorithm.

$\ $3. If we have reached here, then we claim that $G$ has a unique MST.

An ordinary run of Kruskal's algorithm takes $O(|E|\log(|V|))$ time. The extra selection of edges not in $m$ can be done in $O(|E|)$ time. So the algorithm achieves $O(|E|\log(|V|))$ time-complexity.

Why can this algorithm determine if there are multiple MSTs?

Suppose we have an MST $m'$ that is not the same as $m$. It is enough to show that the algorithm running on $G$ will not reach step 3, since the edge found at the end of step 2, which is not in $m$ and connecting two different trees would have been included in the resulting MST had we run Kruskal's algorithm to completion. Let $w$ be the largest weight such that for any edge weighing less than $w$, it is in $m$ if and only if it is in $m'$. Because $m$ and $m'$ have the same number of edges of weight $w$, there exist edges of weight $w$ that are in $m'$ but not in $m$. If the algorithm has exited before processing edges of those edges, we are done. Otherwise, suppose the algorithm is going to process the first edge $e'$ among those edges now. Let $S$ be the set of all edges that have been preserved so far to be included in the resulting MST. $S\subset m$. Since the algorithm have not finished processing edge of weight $w$ not in $m$ such as $e'$, it must have not begun processing edges of weight $w$ in $m$. So edges in $S$ weigh less than $w$. That means $S\subset m'.$ Recall that $e'$ is in $m'$. Since $\{e'\}\cup S\subset m'$, where $m'$ is a tree, $e'$ must connect two different trees in $S$ and the algorithm exits at this point.

Note on further development
Step 1 and step 2 can be interleaved so that we can terminate the algorithm as soon as possible without processing of edges of greater weights.
In case you want to compute the number of MSTs, you may check an answer to how to compute the number of MSTs.