Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE

Problem: An MST is built with Kruskal's algorithm on vertices 0–4 and edges: 0-1 (4), 0-2 (1), 1-2 (2), 1-3 (5), 2-3 (8), 3-4 (3), 2-4 (7). What is the total weight of the minimum spanning tree?

  1. A. 24
  2. B. 10
  3. C. 11
  4. D. 6

Correct answer: C. 11

Kruskal takes 0-2 (1), 1-2 (2), 3-4 (3), skips 0-1 (4, cycle) and takes 1-3 (5): 1 + 2 + 3 + 5 = 11. Taking the four lightest edges without a cycle check gives 10, stopping after three edges leaves a component disconnected (6), and sorting in descending order gives the maximum spanning tree (24).

More Coding Interview Problems questions

Exams that ask this topic