Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

An undirected graph on 6 vertices has the edges E–Z, E–K, E–W, Z–K, Z–F, Z–H, Z–W, K–F, K–W. How many simple paths (no repeated vertex) go from E to W? Paths are counted as vertex sequences, so each route is counted once.

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

Correct answer: B. 7

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