Data Structures & AlgorithmsModerateGATE CS · ICPC regional

Undirected weighted graph on vertices A to G with edges listed as: B–G (5), D–F (8), E–F (8), B–E (1), D–G (5), A–F (9), D–E (1), E–G (8), A–G (9), C–E (5), A–B (9). 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. D–G (5)
  2. B. B–G (5)
  3. C. D–F (8)
  4. D. C–E (5)

Correct answer: D. C–E (5)

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic