Data Structures & AlgorithmsModerateWipro · Accenture pattern

An undirected graph has edges S–A, S–B, A–C, B–C, B–D, C–E, D–E, E–F. After BFS from S, which vertices are at level 2, and what is the level of F?

  1. A. C only; F at level 4
  2. B. C and D; F at level 4
  3. C. C and D; F at level 3
  4. D. C, D and E; F at level 3

Correct answer: B. C and D; F at level 4

Level 1: A, B. Level 2: C (from A) and D (from B). Level 3: E. Level 4: F. E is reached first through C or D, which are both at level 2, so it cannot be at level 2 itself.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic