Data Structures & AlgorithmsHardIBM · Deloitte pattern

An undirected graph has edges (u–v: weight) A–B:4, B–D:7, A–D:15, A–C:29, B–C:28, C–D:29. What is the weight of its minimum spanning tree?

  1. A. 54
  2. B. 112
  3. C. 26
  4. D. 39

Correct answer: D. 39

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 39. Simply taking the 3 globally lightest edges without checking for cycles can give a different (and possibly disconnected or cyclic) total, 26.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic