5
$\begingroup$

I have been cracking my head over the following question -

You are given an undirected connected graph with an even number of edges. Half of the edges have weight less than C (possibly with repetitions), and the other half of edges all have weight C. Is it true that every MST of the graph includes the same number of edges of weight C?

If Yes, describe an efficient algorithm for finding the number of edges of weight C in every MST of the graph. The output is between 0 and |E| / 2, no need to return the MST.

If No, show a counterexample.

My work so far -

I've managed to prove to myself that the number of C weighing edges included in a spanning tree (not minimum) can be anywhere between 0 and |E| / 2 (using a cycle with C edges crossing it).

Obviously, I couldn't find a counterexample yet. It feels like what's preventing me from creating two different MST's with a different number of C edges is that for creating a graph that has more than one MST you need to have cycles, and if a C edge is contained in the cycle it won't be chosen (Kruskal). That is the direction I'm leaning towards for a proof, proving a more general claim obviously.

Assuming the above is in fact true, I need to show an efficient algorithm for finding the number of C edges in every MST. The question states there is no need to return an MST, so it seems like there should be a better algorithm than finding the MST and counting the number of C edges in it, meaning this algorithm should be more efficient than sorting. From what I showed above, it could be anywhere between 0 and |E| / 2 so I'm kinda lost here too.

$\endgroup$
1

2 Answers 2

3
$\begingroup$

All spanning trees have the same number of edges of each weight, as shown by Raphael as an answer to a question in that direction (thanks hengxin).

How to we count the number of heavy edges, of weight $C$, without computing the MST explicitly? First ignore the heavy edges. Also ignore the weights of the remaining edges. Determine the number $k$ of connected components in the resulting graph of light edges. The number of heavy edges then equals $k-1$. Here I assume all nodes in the graph are reachable.

$\endgroup$
4
  • $\begingroup$ Looks great. What do you mean by "Also ignore the weights of the remaining edges" ? $\endgroup$
    – Ben Danon
    Apr 9, 2015 at 12:46
  • $\begingroup$ With "ignoring the weights" I mean they are not important when constructing the connected components. (You do not need to perform any action to dispose of the weights, just don't look at them.) $\endgroup$ Apr 9, 2015 at 12:49
  • $\begingroup$ As I understood your solution, I should "remove" all the edges of weight C from the graph and then run an augmented DFS (or such) to get the number of connected components (call it k) . The number of C edges in all the MSTs is k - 1. Complexity is O(n + m). Am I right? $\endgroup$
    – Ben Danon
    Apr 9, 2015 at 13:02
  • $\begingroup$ That is indeed my observation. $\endgroup$ Apr 9, 2015 at 21:11
3
$\begingroup$

If the answer is "yes", then there is an easy algorithm: just compute any MST and report the number of edges with weight $C$. If they all have the same number of edges with weight $C$, then the particular MST you compute won't change the answer.

So now you want to know whether the answer is yes. To see that it is, observe that each MST is constructed by running the greedy algorithm on a specific linear extension of the partial order induced by the weights. In your case, the edges $E$ partitioned into sets $E_{<C}$ and $E_C$, and every edge in $E_{<C}$ comes before any edge in $E_C$ for all of these linear extensions. That tells you that every MST is made of a spanning forest $F$ on the subgraph induced by $E_{<C}$ and some edges from $E_C$; since all the choices for $F$ have the same size, we are done.

$\endgroup$
2
  • $\begingroup$ 1. Is the algorithm you mentioned in the first paragraph the most efficient? I mentioned it above but thinking there might be a better one. $\endgroup$
    – Ben Danon
    Apr 9, 2015 at 12:35
  • $\begingroup$ Just figure out how many connected components $E_{<C}$ has. If there are $c$ of them, the number of edges in a spanning forest of $E_{<C}$ is just $n - c$. $\endgroup$
    – Louis
    Apr 9, 2015 at 12:59

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.