BeginnerAbout 25 min
Breadth-First Search (BFS)
Read the full article on Substack
6 min read.
A fundamental graph traversal algorithm. It explores all neighbor nodes at the present depth prior to moving on to the nodes at the next depth level. It guarantees the shortest path in an unweighted graph.
Think of it this way: Think of dropping a stone in a calm pond. Ripples spread out in circles, reaching everything at distance 1, then distance 2. BFS explores 'ripples' layer by layer.
Start at (4,1), goal (4,11).
1/219
Check your understanding
Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.
Breadth-first, level by level
Sequence
Order the steps of BFS from a source node.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
5 pieces left to place
Quiz
20 questionsQuestion 1 of 20
Score: 0
Does BFS guarantee the shortest path?
Done with this lesson?
Sign in free to keep your progress, streak and quiz scores.