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.
- A. C–E (weight 1)
- B. B–D (weight 8)
- C. A–C (weight 3)
- 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.
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
- Directed weighted graph on vertices A, B, C, D, E with edges A→C (4); C→E (-2); D→C (-4); D→B (2); D→E (-1); D→A (1); E→D (6); E→C (-2)…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–E (1), A–G (1), B–C (1), B–F (1), B–G (1), C–F (1), C–G (1)…
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 15, 18, 8, 2, 3, 20], where Mi has size p[i−1] × p[i]…
- Strings a = "bccbc" and b = "bbacaa". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- 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→C (9)…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (2), A–D (1), B–C (2), B–D (2), C–D (1). How many distinct…