Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

In the undirected connected graph on vertices 0 to 8 with edges 0-1, 0-3, 0-4, 0-5, 1-2, 1-3, 2-4, 2-5, 2-6, 3-7, 5-6, 7-8, how many vertices are at distance exactly 2 from vertex 0? Distance means the fewest edges.

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

Correct answer: C. 3

A BFS from vertex 0 assigns each vertex its level. The question asks for one level only, not the cumulative count up to that level.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic