Data Structures & AlgorithmsModerateTCS NQT · Graphs

An undirected graph has edges A-B, A-C, B-D, B-E, C-E, C-F, D-G, E-G, F-G. Neighbours are always visited in alphabetical order. What is the breadth-first traversal order starting from A?

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

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

BFS visits A, then its neighbours B and C, then D, E (from B), F (from C), and finally G.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic