Algorithms

Breadth-first search (BFS)

Walking a tree or graph level by level: first the ones closest to the start, then the next ones. It uses a queue.

Example

With root 1, children 2 and 3, and grandchildren 4, 5, 6 and 7, BFS visits 1, 2, 3, 4, 5, 6, 7.

Test yourself: Breadth-first search (BFS)

Walking a tree

What structure does level-order traversal use?

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.