Data Structures & AlgorithmsHardGATE CS · TCS NQT

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

  1. A. 31
  2. B. 91
  3. C. 60
  4. D. 50

Correct answer: A. 31

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