Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern

An undirected graph has edges (u–v: weight) A–C:16, B–C:30, C–D:17, A–D:2, A–B:3, B–D:12. What is the weight of its minimum spanning tree?

  1. A. 23
  2. B. 21
  3. C. 17
  4. D. 80

Correct answer: B. 21

Kruskal's algorithm sorts edges by weight and adds the cheapest one that does not form a cycle (checked with union-find) until all vertices are connected, giving a total MST weight of 21. Simply taking the 3 globally lightest edges without checking for cycles can give a different (and possibly disconnected or cyclic) total, 17.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic