Data Structures & AlgorithmsHardGATE CS · ICPC regional

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

Correct answer: C. A–D (2)

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic