Data Structures & AlgorithmsHardAccenture · Infosys OA

Problem: Which traversal order is guaranteed to visit nodes level by level in a tree or graph?

  1. A. Post-order traversal
  2. B. In-order traversal
  3. C. Depth-first search (DFS), using a stack or recursion
  4. D. Breadth-first search (BFS), using a queue

Correct answer: D. Breadth-first search (BFS), using a queue

BFS processes all nodes at distance k from the source before any node at distance k+1, which is exactly level-by-level order; DFS instead dives deep along one branch first.

More Coding Interview Problems questions

Exams that ask this topic