Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

A connected undirected weighted graph on vertices 0 to 4 has the edges (u-v with weight): 0-1 (w=9), 0-2 (w=5), 0-3 (w=11), 1-2 (w=7), 1-3 (w=1), 1-4 (w=7), 2-3 (w=2), 2-4 (w=4), 3-4 (w=14). What is the total weight of a minimum spanning tree?

  1. A. 21
  2. B. 12
  3. C. 41
  4. D. 60

Correct answer: B. 12

Kruskal's algorithm takes edges in increasing weight and skips any edge that closes a cycle. Adding the n − 1 lightest edges ignores cycles, and taking edges in input order is not minimal.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic