Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

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

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

Correct answer: D. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic