Data Structures & AlgorithmsVery hardProduct-company placement

The weighted undirected graph A–B (6), A–D (16), A–E (19), A–F (12), B–E (1), B–F (2), C–D (26), C–E (14) has a unique MST. What is the weight of the SECOND-best spanning tree (the lightest spanning tree different from the MST)?

  1. A. 45
  2. B. 39
  3. C. 51
  4. D. 49

Correct answer: A. 45

The MST weighs 39. A second-best tree swaps exactly one MST edge for one non-tree edge that closes a cycle through it; the best swap adds 6, giving 45. Adding the lightest non-tree edge without removing the heaviest edge on its cycle is the trap.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic