Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 D

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

  1. A. 54
  2. B. 31
  3. C. 27
  4. D. 24

Correct answer: C. 27

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic