Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE

Problem: Vertices 0–5 are connected by weighted undirected edges: 0-1 (2), 0-2 (4), 1-2 (1), 1-3 (7), 2-4 (3), 3-4 (2), 3-5 (1), 4-5 (5). What is the total weight of the minimum spanning tree (Kruskal's algorithm)?

  1. A. 9
  2. B. 21
  3. C. 25
  4. D. 6

Correct answer: A. 9

Kruskal takes 1-2 (1), 3-5 (1), 0-1 (2), 3-4 (2), 2-4 (3): total 9. Heaviest-first gives the maximum spanning tree (21), 25 sums every edge, and stopping at four edges gives 6.

More Coding Interview Problems questions

Exams that ask this topic