Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS

A connected undirected graph has the vertices N, R, U, W, Z and weighted edges (weights in brackets): W–R (7), R–N (1), U–R (16), U–Z (5), W–N (14), U–N (11), W–U (16), R–Z (12). What is the total weight of a minimum spanning tree?

  1. A. 25
  2. B. 58
  3. C. 24
  4. D. 36

Correct answer: C. 24

Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 24. A heaviest-first spanning tree gives 58, and a shortest-path tree rooted at W gives 36.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic