Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Undirected weighted graph on vertices A to G with edges listed as: D–F (6), B–C (5), D–E (3), A–B (6), A–F (5), D–G (3), C–G (6), A–G (5), E–G (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 third edge that Kruskal ADDS?

  1. A. E–G (4)
  2. B. D–G (3)
  3. C. B–C (5)
  4. D. A–F (5)

Correct answer: C. B–C (5)

Kruskal accepts D–E (3), D–G (3), B–C (5), A–F (5), A–G (5), A–B (6) in that order, so the third accepted edge is B–C (5). Taking the 3-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