Data Structures & AlgorithmsVery hardProduct company OA

Weighted undirected graph: A–B 1, B–C 2, C–A 2, C–D 1, B–D 2. How many DIFFERENT minimum spanning trees does it have?

  1. A. 1
  2. B. 2
  3. C. 4
  4. D. 3

Correct answer: D. 3

Both weight-1 edges (A–B, C–D) are always taken. They leave two components {A, B} and {C, D}, and every weight-2 edge (B–C, C–A, B–D) joins them. Any one of the three completes an MST of weight 4, so there are 3 MSTs. Kruskal returns just one of them, depending on how ties are broken.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic