Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Kruskal's algorithm on the edges 0-1 (3), 1-2 (1), 0-2 (2), 2-3 (5), 1-3 (4), 3-4 (2), 2-4 (6) processes the edges in increasing weight order. Which edge is the fourth one added to the spanning tree? Report its weight.

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

Kruskal adds the cheapest edge that does not close a cycle, so the sequence of accepted weights is nondecreasing. Skipping the cycle test accepts extra heavy edges and changes the fourth value.

More Coding Interview Problems questions

Exams that ask this topic