Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

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

  1. A. 4
  2. B. 8
  3. C. 2
  4. D. 9

Correct answer: B. 8

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic