Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 D

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

  1. A. 59
  2. B. 46
  3. C. 25
  4. D. 27

Correct answer: D. 27

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic