Which data structure is commonly used to implement Breadth-First Search (BFS)?

Options

  • A. Stack
  • B. Queue
  • C. Binary Search Tree
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

B. Queue

Detailed Explanation

Breadth-First Search (BFS) generally uses a Queue to visit vertices level by level. Starting from a source vertex, BFS visits its immediate neighbors first and then proceeds to the next level. A queue ensures that vertices are processed in the same order in which they are discovered. BFS is useful for finding the shortest path in an unweighted graph. In contrast, Depth-First Search (DFS) commonly uses a stack or recursion.