Data Structures & AlgorithmsModerateGATE CS · ICPC regional
Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: A–D (2), A–C (3), A–F (6), B–C (5), D–E (5), D–F (2), C–F (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. D–F (weight 2)
- B. A–D (weight 2)
- C. A–F (weight 6)
- D. C–F (weight 8)
Correct answer: A. D–F (weight 2)
Scanning in the listed order, the first edge that closes a cycle is D–F (weight 2). 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
- Complete undirected graph on vertices A to E with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Strings a = "bcbbba" and b = "accc". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Words ['ca', 'aa', 'dc', 'ab', 'dad', 'aca', 'aac'] (each may be used at most once). A chain is a sequence of these words in which the…
- Directed graph on vertices A, B, C, D, E, F, G with edges C→A, E→A, E→G, G→C, G→F, F→C, C→G, C→B (no weights). What is the number of…
- On an 8 × 8 chessboard with rows and columns numbered 0 to 7, a knight starts at (4, 7) and must reach (1, 0) (as (row, column)). A knight…
- A trie keeps a counter at each node, and every word of the list W = ['bbaa', 'bc', 'a', 'cbaa', 'ccac', 'a'] is inserted once per…