In breadth first search of graph, which of the following data structure is used?

By: Prof. Dr. Fazal Rehman Shamil | Last updated: February 3, 2024

Question: In breadth first search of graph, which of the following data structure is used?

A   Stack

B   Queue

C   Linked list

D   None of the above

Answer:   Queue

 

Data StructurePurpose in BFS
Queue

 

 

 

In breadth-first search (BFS) of a graph, a Queue is typically used as the data structure. BFS explores all the neighbor nodes at the current depth before moving on to nodes at the next depth level. A queue is well-suited for this because it follows the First-In-First-Out (FIFO) principle, ensuring that nodes are processed in the order they were added to the queue, which matches the behavior of BFS.
StackNot typically used in BFS.
Linked ListMay be used as part of the implementation, but it is not the primary data structure for BFS.