Data Structures & AlgorithmsModerateGATE CS · Product-company placement

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

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

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

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 G H C B D F.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic