Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

A connected undirected graph has the vertices E, H, O, P, V, W, X and weighted edges (weights in brackets): E–P (4), O–W (16), X–H (8), V–P (7), O–H (11), E–H (12), X–W (20), V–H (4), E–V (10), O–P (11), O–V (11). What is the total weight of a minimum spanning tree?

  1. A. 50
  2. B. 81
  3. C. 51
  4. D. 44

Correct answer: A. 50

Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 50. A heaviest-first spanning tree gives 81, and a shortest-path tree rooted at O gives 61.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic