Imagine you're standing in a huge place, a maze, a city, a cave, or a game world. Somewhere around you is something you're looking for: a treasure, a friend, an exit, or a charging station. You cannot see the entire area, so you have to discover new places as you move.
From where you are, you can only see the places directly connected to your current location. As you explore, each place may lead you to several more places, gradually revealing more of the surroundings.
Let's play a game where you'll explore a set of connected places to find a nearby target. Follow the available paths carefully and decide which places to explore first so that you can find the target as quickly as possible without unnecessarily going farther away.
Let's see exactly what that looks like π
It's a birthday, and a gift is hidden somewhere inside the house. The child starts at the Front Door, you decide which room gets checked next. Only nearby rooms will glow, click one. Watch closely as you play. There's a pattern here worth noticing.
NOTE: Play manually by clicking glowing rooms, or press Start Auto-Play to watch it happen, your choice!
The child is standing at the Front Door. Click a glowing room to check it.
Here's the order you checked rooms in, notice how it moved floor by floor:
Curious why this pattern always works? Head to the Blueprint Room for the full breakdown, plus a quick animated demo.
Sit with these for a moment, there's no single "correct" wording, just think them through in your own words.
Tap a card to open it up and see the idea behind what you just did.
Here's the exact same strategy, on a simple tree this time. Press play and watch the order it lights up in.
This is Breadth-First Search (BFS)! Here's what you just discovered in the house:
| You (the searcher) | β the algorithm doing the traversal |
| A Room | β a node in the graph |
| A Doorway / Staircase | β an edge connecting two nodes |
| "Only nearby rooms glow" | β only unvisited neighbours join the frontier |
| Checking all rooms on a floor first | β visiting every node at the current level before the next |
This level-by-level strategy is exactly why BFS always finds the shortest path in an unweighted graph: nothing farther away is ever checked before everything closer has been. π
New situations to think through using what you just discovered.