Algorithms and Data Structures · Junior · Question 54 of 75
Which data structure does breadth-first search (BFS) use?
- 1A stack
- ✓Correct answer: A queue
- 3A heap
Explanation
BFS takes the oldest discovered node next, which is FIFO: neighbors of the current level are processed before the next level. Replacing the queue with a stack turns it into DFS.