Data Structures & AlgorithmsModerateCognizant · Capgemini pattern

An undirected graph has edges A–B (2), A–C (3), B–C (1), B–D (4), C–D (5), C–E (6), D–E (2). What is the total weight of its minimum spanning tree?

  1. A. 12
  2. B. 10
  3. C. 9
  4. D. 8

Correct answer: C. 9

Kruskal takes B–C (1), A–B (2), D–E (2), skips A–C (3) because it closes a cycle, then takes B–D (4): 1 + 2 + 2 + 4 = 9. Taking A–C instead of A–B, or forgetting to skip it, gives 10 or 12.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic