Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

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

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

Correct answer: A. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic