Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 D

Undirected connected weighted graph on vertices 0 to 5 with edges (u–v (w)): 2–5 (11), 0–4 (12), 1–3 (8), 0–1 (9), 2–3 (2), 2–4 (3), 0–5 (4), 1–2 (1), 0–3 (9). What is the total weight of a minimum spanning tree?

  1. A. 19
  2. B. 45
  3. C. 35
  4. D. 18

Correct answer: A. 19

Kruskal adds edges in increasing weight and skips any edge that closes a cycle, giving total 19. The heaviest spanning tree (45), the shortest-path tree from 0 (35) and a blind sum of the n−1 lightest edges (18) are the traps.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic