Data Structures & AlgorithmsVery hardProduct-company placement

The weighted undirected graph A–E (19), A–F (20), B–F (2), C–D (25), C–E (10), C–F (7), D–E (18), D–F (8) has a unique MST. What is the weight of the SECOND-best spanning tree (the lightest spanning tree different from the MST)?

  1. A. 46
  2. B. 64
  3. C. 47
  4. D. 54

Correct answer: C. 47

The MST weighs 46. A second-best tree swaps exactly one MST edge for one non-tree edge that closes a cycle through it; the best swap adds 1, giving 47. 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