Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 D

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

  1. A. 67
  2. B. 38
  3. C. 34
  4. D. 35

Correct answer: D. 35

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic