Data Structures & AlgorithmsModerateCodeforces Div 2 B · GATE CS

Connected simple undirected graph on vertices 0 to 6 with edges: 2–4, 0–1, 1–6, 5–6, 0–3, 3–4, 1–5, 2–3, 0–6, 2–5, 4–5. 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)?

  1. A. 3
  2. B. 6
  3. C. 2
  4. D. 4

Correct answer: C. 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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic