Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

Unweighted directed graph on vertices 0 to 8 with edges: 4→2, 4→8, 3→0, 0→2, 0→4, 4→7, 6→4, 3→8, 2→5, 2→1, 1→4, 2→7, 2→8, 3→7, 4→6. How many shortest paths (fewest edges) lead from 0 to 8? Two paths are different if their vertex sequences differ.

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

Correct answer: B. 2

BFS finds distance 2 and 2 shortest paths, counted level by level. Counting every simple path (4) or ignoring directions (3) are the traps; 5 vertices sit at that distance.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic