Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

An undirected graph has adjacency lists A:BCDE B:AC C:ABE D:AG E:ACF F:EH G:DH H:FG. Neighbours are always explored in alphabetical order. Which is the BFS visiting order starting at A?

  1. A. ABCDEGFH
  2. B. ABCEFHGD
  3. C. HFGEDCBA
  4. D. ACBDEGFH

Correct answer: A. ABCDEGFH

BFS explores level by level with a queue, taking neighbours in alphabetical order, giving ABCDEGFH.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic