Data Structures & AlgorithmsHardGATE CS · ICPC regional

Undirected weighted graph on vertices A to F with edges listed as: C–D (8), A–F (2), B–E (8), B–D (7), A–B (3), B–F (2), D–E (2). Kruskal's algorithm sorts the edges by increasing weight, breaking ties in listed order, and ADDS each edge that does not close a cycle. Which edge is the fourth edge that Kruskal ADDS?

  1. A. A–B (3)
  2. B. D–E (2)
  3. C. B–D (7)
  4. D. C–D (8)

Correct answer: C. B–D (7)

Kruskal accepts A–F (2), B–F (2), D–E (2), B–D (7), C–D (8) in that order, so the fourth accepted edge is B–D (7). Taking the 4-th lightest edge without the cycle test (A–B (3)) is the slip.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic