Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 B

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

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

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