Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

Correct answer: A. E–G (5)

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic