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 Structure | Purpose 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. |
Stack | Not typically used in BFS. |
Linked List | May be used as part of the implementation, but it is not the primary data structure for BFS. |