Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: B–E (3), C–E (4), B–C (8), E–F (2), D–F (7), A–F (7), B–F (4), A–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. B–E (weight 3)
- B. B–F (weight 4)
- C. B–C (weight 8)
- D. A–E (weight 8)
Correct answer: C. B–C (weight 8)
Scanning in the listed order, the first edge that closes a cycle is B–C (weight 8). 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 [28, 17, 3, 22, 8, 23, 10] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges A–D, A–E, B–F, B–G, C–D. What is the size of a maximum…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→B (4)…
- Points A(8,5), B(3,9), C(3,5), D(2,7), E(3,2) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Directed weighted graph on vertices A, B, C, D, E with edges D→C (0); B→D (2); A→D (-1); E→A (-1); B→C (0); B→A (-2); C→E (4); D→E (-1)…
- Array A = [7, 4, 7, 14, 7, 6, 2]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…