Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2

Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: B–D (8), A–E (3), C–D (8), A–C (3), C–F (4), C–E (1), A–F (7), E–F (3). Run union–find cycle checking over the edges in the LISTED order (an edge is rejected when both its ends are already connected). Which edge is the first one rejected? Answer as the edge with its weight.

  1. A. C–E (weight 1)
  2. B. B–D (weight 8)
  3. C. A–C (weight 3)
  4. D. E–F (weight 3)

Correct answer: A. C–E (weight 1)

Scanning in the listed order, the first edge that closes a cycle is C–E (weight 1). Scanning in increasing-weight order rejects a different edge first, which is why the processing order matters for identifying which edge is rejected.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic