1
$\begingroup$

Given some undirected weighted graph $\ G(V,E, w) $ and its minimum spanning tree $\ T$, I need to find another spanning tree $\ T' $ with minimal amount of common edges of both trees. If there are no other spanning trees then $\ T' = T $

I was thinking maybe if I can "subtract" the edges of the minimum spanning tree I was given from the original graph edges and then this subset of edges that I've left with is my starting point for running prim algorithm and if I can not find other MST then any $\ T' = T $ does that make any sense at all ?

$\endgroup$

1 Answer 1

1
$\begingroup$

Instead of "subtract", it is easier to "try to avoid".


Sort all edges first by their weights, then by whether they belong to $T$. In other words, for any two edge $e_1$ and $e_2$, $e_1$ precedes $e_2$ if and only if

  • $w(e_1) \lt w(e_2)$, or
  • $w(e_1) = w(e_2)$ and $e_1$ does not belong to $T$ and $e_2$ belongs to $T$

The above order can also be realized by just increasing all weights of edges in $T$ by a small enough amount, such as $\frac d2$, where $d$ is the minimum positive difference between weights of any two edges.

Run Kruskal's algorithm or Prim's algorithm as usual using the above order of the edges instead of the usual order which sorts the edges by weights only. Since the edges are ordered by their (original) weights still, we will obtain a minimum spanning tree, which is $T'$.


On the other hand, you idea to "subtract" works as well.

Let $S$ be the all edges of $T$. For each edge $e\in S$ from the lightest to the heaviest,

  1. remove $e$ from $T$. $T$ becomes two disjoint trees
  2. check whether there is an edge other than $e$ of the same weight that connects those two disjoint trees.
    • If we are able to find one, add it to $T$.
    • Otherwise there is no such edge. Add $e$ back to $T$.
  3. return $T$, which may or may not have been changed, as $T'$.

However, the algorithm above is harder to implement and probably slower as well.

$\endgroup$
1
  • 1
    $\begingroup$ Yes I like the kruskal suggestion better. neat solution! $\endgroup$
    – bm1125
    Jan 20, 2022 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.