GATE Computer ScienceVery hardGATE CS (PYQ pattern)

An undirected unweighted graph has edges 1-2, 1-3, 2-4, 2-5, 3-4, 3-6, 4-7, 5-7, 6-7, 6-8, 7-9, 8-9. Using BFS from vertex 1, what is the distance to vertex 9 and the number of distinct shortest paths from 1 to 9?

  1. A. distance 4, 4 paths
  2. B. distance 4, 5 paths
  3. C. distance 5, 5 paths
  4. D. distance 4, 8 paths

Correct answer: B. distance 4, 5 paths

BFS layers: {1}, {2,3}, {4,5,6}, {7,8}, {9}. Path counts propagate additively: 4 gets 2, 5 gets 1, 6 gets 1, 7 gets 4, 8 gets 1, so 9 gets 5.

More Programming and Data Structures (GATE) questions

Exams that ask this topic