Data Structures & AlgorithmsModerateGATE CS

An undirected graph has edges A–E, A–H, B–F, C–E, C–G, D–G, D–H, E–F, E–G, F–H. BFS starts at A and always scans neighbours in alphabetical order. In what order are the vertices visited?

  1. A. A E C G D H F B
  2. B. A H F E G D C B
  3. C. A E H C D F G B
  4. D. A E H C F G D B

Correct answer: D. A E H C F G D B

BFS dequeues level by level, and within a level in the order vertices were enqueued (which depends on their parents, not on alphabetical order): A E H C F G D B.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic