Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

Correct answer: A. B–G (4)

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic