Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 B

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

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

Correct answer: C. 2

BFS finds distance 2 and 2 shortest paths, counted level by level. Counting every simple path (10) 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