Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

A connected undirected graph has the vertices E, F, I, Q, S, Z and weighted edges (weights in brackets): E–I (3), F–E (8), Z–S (12), S–I (7), F–I (13), Q–E (17), Z–F (4), Q–I (20), F–Q (18). What is the total weight of a minimum spanning tree?

  1. A. 39
  2. B. 34
  3. C. 45
  4. D. 40

Correct answer: A. 39

Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 39. A heaviest-first spanning tree gives 74, and a shortest-path tree rooted at Z gives 45.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic