Which data structure conveniently used to implement BFS? A. Stacks B. Queues C. Priority Queues D. All of the mentioned

Stacks
Queues
Priority Queues
All of the mentioned

The correct answer is: B. Queues

A queue is a linear data structure in which elements are added at the end (enqueue) and removed from the beginning (dequeue). This makes it a convenient data structure to use for Breadth First Search (BFS), as the next node to be visited is always the one at the front of the queue.

A stack is a linear data structure in which elements are added and removed from the same end (the top). This makes it a convenient data structure for Depth First Search (DFS), as the next node to

be visited is always the one at the top of the stack.

A priority queue is a data structure that stores elements with a priority associated with each element. The elements are then sorted in order of their priority, with the highest priority elements being at the front of the queue. This makes it a convenient data structure for tasks that require elements to be processed in order of their priority, such as scheduling tasks or finding the shortest path between two nodes in a graph.

However, a priority queue is not a convenient data structure to use for BFS, as the next node to be visited is not always the one with the highest priority. In fact, the next node to be visited in BFS is always the one that is closest to the starting node.

Therefore, the correct answer to the question is: B. Queues