Data Structures & AlgorithmsModerateCodeforces Div 2 C · GATE CS

Connected undirected simple graph on vertices 0 to 4 with edges: 0–1, 1–3, 2–4, 1–2, 1–4. What is the maximum number of edges in a simple path (no repeated vertex) in this graph?

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

Correct answer: D. 3

Exhaustive search over simple paths finds a longest one with 3 edges. The largest shortest-path length (2) measures a different thing, and n−1 assumes a Hamiltonian path that need not exist.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic