Data Structures & AlgorithmsVery hardProduct company OA

Weighted undirected graph: A–B 1, B–C 2, C–D 3, D–A 4, A–C 5, B–D 6. The MST is unique. What is the weight of the SECOND-best spanning tree (the cheapest spanning tree different from the MST)?

  1. A. 6
  2. B. 7
  3. C. 15
  4. D. 21

Correct answer: B. 7

MST: A–B 1, B–C 2, C–D 3 = 6. The cheapest different tree adds D–A 4 and drops C–D 3 from the cycle A-B-C-D: 1 + 2 + 4 = 7. 6 is the MST itself, 15 the maximum spanning tree (6 + 5 + 4) and 21 the sum of all edges.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic