Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2
Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: A–C (1), B–C (8), B–D (5), D–E (6), C–E (7), B–E (8). 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.
- A. A–C (weight 1)
- B. B–C (weight 8)
- C. B–E (weight 8)
- D. C–E (weight 7)
Correct answer: D. C–E (weight 7)
Scanning in the listed order, the first edge that closes a cycle is C–E (weight 7). Scanning in increasing-weight order rejects a different edge first, which is why the processing order matters for identifying which edge is rejected.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(9) and count every invocation of f…
- A binary tree with distinct letters has preorder DAEFCB and inorder EADCFB. What is its postorder traversal (left, right, root), written…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–E (1), A–F (1), B–D (1), E–F (1) (weights ignored)…
- 5 × 4 grid, rows top to bottom ('#' = blocked, '.' = open): ..#. / ...# / ...# / ..#. / ..... Count the paths from top-left to…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: B–D (1), A–D (1), B–F (1), C–D (1), D–F (1), B–E (1)…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(7) and count every invocation of f…