Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 B

An undirected graph on 5 vertices has the edges T–X, X–L, X–B, L–B, L–N, B–N. How many simple paths (no repeated vertex) go from T to N? Paths are counted as vertex sequences, so each route is counted once.

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

Correct answer: A. 4

A DFS that extends the path through unvisited neighbours enumerates every simple route, giving 4. 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