Algorithms and Data Structures · Junior · Question 54 of 75

Which data structure does breadth-first search (BFS) use?

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.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 54

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz