1

I am asked to write an algorithm that finds the Minimum Spanning Tree in a graph G, but with the condition that each vertex of G be a leave in the spanning Tree T. How can this be possible if the graph has more than 2 elements? Suppose G contains the vertices a,b and c, the Spanning tree will might something like a--b--c, so in this case b is not a leaf.

I am not looking for a solution to the algorithm, I only want to understand how a Spanning Tree can be composed exclusively of leaves.

Here is the exact wording of the question Question

Thanks for the help

user1354784
  • 386
  • 4
  • 15
  • Commenting here, so the others won't get bothered: I cannot see in the problem statement, that the costs c_e must be all different. If this would be the case, than the problem is a no-brainer, because there is a unique MST and your aproach would work. However, I don't think it is how the problem is meant to be. – ead Feb 16 '16 at 15:26

1 Answers1

4

The question states that S is a subset of the vertices V in the graph. There may be non-leaf nodes. However, you have to make sure that these internal nodes are not in S. If S would be equal to V you'd be right.

lex82
  • 11,173
  • 2
  • 44
  • 69
  • Thanks, what I ended up doing is using Boruvka to get the MST and then iterating through each node and comparing them to the vertices in the set. If they are the same, I check if the node has no children, otherwise the MST is not feasible. – user1354784 Feb 15 '16 at 05:04
  • @user1354784 I don't think your approach would work, because MST is not unique and you cannot be sure, that Boruvka (or any standard algorithm else) will pick the right MST. There can be some MST which fulfill the constrain about leaves and some which don't. – ead Feb 15 '16 at 14:56
  • I think we can assume that all edges have distinct values – user1354784 Feb 15 '16 at 16:58
  • @user1354784 I think you may have misinterpreted the question. The question is asking to find the MST subject to the condition where none of the internal vertices of the above found MST come from the set S. You, on the other hand, have found a generic MST and are now testing whether it satisfies the constraints or not. – Shubham Mittal Aug 01 '16 at 21:52