Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: B–D (7), A–D (7), C–D (9), D–E (3), A–C (2), C–E (2), B–E (3), A–E (3), A–B (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. A–B (weight 3)
- B. A–C (weight 2)
- C. A–E (weight 3)
- D. B–D (weight 7)
Correct answer: B. A–C (weight 2)
Scanning in the listed order, the first edge that closes a cycle is A–C (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
- Directed weighted graph on vertices A, D, B, F, C (source A, target C) with edges: A→D (4); A→B (7); B→D (-6); D→C (3); B→C (1); A→C (12)…
- Directed acyclic graph on vertices A, B, C, D, E with edges A→D, A→C, D→B, D→C. Among all topological orderings (every edge goes from…
- Words ['b', 'b', 'b', 'c', 'cbca', 'aca'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–D (5), B–D (7), B–F (13), C–D (11), D–E (11), D–F (12), E–F…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→F, C→G, B→E, E→D, E→G, C→E, F→D, C→A, D→A, F→E. How many strongly connected…
- Directed graph on vertices A, B, C, D, E, F with edges C→F, D→E, D→B, F→B, F→C, E→C, F→E, E→A (no weights). What is the number of vertices…