Data Structures & AlgorithmsVery hardCodeforces Div 2 B · GATE CS
Connected simple undirected graph on vertices 0 to 5 with edges: 1–2, 2–4, 2–5, 0–3, 1–5, 0–4, 2–3, 0–2, 0–1, 0–5, 3–4. What is the minimum number of new edges (each joins two distinct vertices; parallel edges allowed) that must be added so the graph has an Euler trail (a walk that uses every edge exactly once; start and end may differ)?
- A. 3
- B. 2
- C. 6
- D. 4
Correct answer: B. 2
Only odd-degree vertices obstruct a trail, and a trail may have two of them. With 6 odd vertices, each new edge fixes two of them, so (k−2)/2 = 2 new edges are needed. The Euler circuit version would need 3.
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
- Connected simple undirected graph on vertices 0 to 7 with edges: 2–4, 0–2, 1–3, 3–5, 2–5, 4–7, 2–7, 0–4, 6–7, 3–6, 0–6, 1–6, 2–6, 1–7…
- Connected simple undirected graph on vertices 0 to 7 with edges: 1–6, 2–3, 0–6, 0–3, 1–7, 1–4, 0–5, 0–2, 1–3, 0–1, 2–5. What is the…
- Directed weighted graph on vertices 0 to 5 with edges (u→v (w)): 5→0 (5), 1→4 (7), 0→1 (5), 2→1 (1), 2→5 (9), 2→0 (2), 5→2 (1), 0→3 (9)…
- Directed weighted graph on vertices 0 to 4 with edges (u→v (w)): 0→3 (7), 2→4 (1), 1→4 (5), 3→2 (5), 4→0 (3), 1→2 (8). Compute the sum of…
- Directed weighted graph on vertices 0 to 3 with edges (u→v (w)): 2→1 (2), 0→1 (7), 1→2 (5), 1→3 (1), 1→0 (5). Compute the sum of the…
- Directed weighted graph on vertices 0 to 4 with edges (u→v (w)): 2→3 (2), 0→3 (1), 0→4 (4), 0→2 (2), 3→1 (5), 2→0 (5), 3→0 (9), 4→2 (9)…