Data Structures & AlgorithmsHardICPC regional · GATE CS

An unweighted undirected connected graph on vertices 0 to 5 has edges 0-1, 0-2, 0-4, 0-5, 1-2, 1-3, 1-4, 1-5, 2-3, 2-4, 3-5. How many different shortest paths (fewest edges) are there from vertex 3 to vertex 0?

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

Correct answer: B. 3

Count shortest paths with BFS: a vertex's count is the sum of the counts of its neighbours one level closer. Counting all simple paths, or just the BFS distance, does not answer the question.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic