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–E (2), D–F (6), B–C (8), C–D (4), A–B (7), A–F (6), E–F (7), C–F (2), A–C (4). 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–E (weight 2)
- B. A–C (weight 4)
- C. A–F (weight 6)
- D. D–F (weight 6)
Correct answer: C. A–F (weight 6)
Scanning in the listed order, the first edge that closes a cycle is A–F (weight 6). 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
- Array A = [4, 3, 9, 3, 3, 9, 7] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Distinct words ['aa', 'ab', 'ca', 'c', 'bb'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–C (1), A–E (1), B–C (2), B–D (3), C–E (1), D–E (3). How many…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): C→D (8); E→C (4); D→C (8); C→E (6); D→A (4); B→E (5). Let d(x, y)…
- Weighted tree on vertices 0 to 5 with edges 0–1 (9), 0–2 (8), 1–3 (4), 3–4 (4), 1–5 (3). What is the largest possible sum of edge weights…
- A binary tree with distinct letters has preorder DFEACB and inorder FDACEB. What is its postorder traversal (left, right, root), written…