Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 D

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

  1. A. 51
  2. B. 33
  3. C. 19
  4. D. 14

Correct answer: C. 19

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic