Data Structures & AlgorithmsHardGATE CS · ICPC regional

An undirected graph on 5 vertices has the edges C–J, C–D, C–P, J–D, J–P, D–P, P–Z. How many simple paths (no repeated vertex) go from C to Z? Paths are counted as vertex sequences, so each route is counted once.

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

Correct answer: B. 5

A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 5. Counting only the shortest routes gives 1, which is a much smaller set.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic