Worked example
On an open 3ร3 grid, start in the top-left corner and aim for the bottom-right. Breadth-first search checks cells one move away, then two moves away. The first time it reaches the goal, it can trace back a route with four moves.
๐ป Coding games ยท free, no sign-up
Loading Pathfinding Visualizerโฆ
Learn beyond the game
On an open 3ร3 grid, start in the top-left corner and aim for the bottom-right. Breadth-first search checks cells one move away, then two moves away. The first time it reaches the goal, it can trace back a route with four moves.
Visited cells show where the search looked; they are not all part of the final route. Breadth-first search may explore several branches before it can prove that a shortest route has been found.
Draw a 5ร5 grid, add a few walls, and use scraps of paper as a queue. Put the start cell in first, then add each open neighbour once. Mark the distance layer as you go.
On a 3ร3 grid, block only the centre cell. From the top-left to the bottom-right, what is the shortest distance, and how many shortest routes avoid the wall?
The shortest distance is four moves. Two shortest routes avoid the centre: go across the top then down, or down the left side then across the bottom.
Run the search on the ready-made maze, then add one wall at a time and compare how many cells are visited. For a different algorithmic idea, try the Sorting Visualizer.
This grid gives every move the same cost. When routes have different costs, algorithms such as Dijkstra's search keep track of the total cost as well as the number of steps.
Keep playing
FAQ
No. It is a small grid demonstration of breadth-first search; real maps include roads, travel time and many other constraints.
Yes. Click cells to place or remove walls, then run the search.
Start a conversation
A parent or guardian can share the learner's age, level and goals, and we'll suggest a starting point and confirm the format before anything is booked.