Data Structures & AlgorithmsModerateGATE CS · TCS NQT

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

  1. A. 84
  2. B. 49
  3. C. 109
  4. D. 45

Correct answer: B. 49

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