Which data structure is used to implement a breadth-first search in a tree?
a) Stack
b) Queue
c) Priority Queue
d) Array
Answer:
b) Queue
Explanation:
Breadth-First Search (BFS) in a tree is implemented using a queue data structure. BFS explores the tree level by level, starting from the root and visiting all nodes at the current level before moving to the next.
The queue allows nodes to be processed in the order they are discovered, ensuring that all children of a node are visited before moving deeper into the tree.
BFS is useful for finding the shortest path in unweighted trees or graphs and for level-order traversal of a tree.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers