Animation11 min
BFS Wave vs DFS Tendril
The two traversals contrasted on the same graph.
This animation runs both traversals over the same grid maze, and the contrast is the lesson. In BFS mode, the start cell pulses and concentric colored waves flood outward — one distance-ring per tick, each ring a deeper hue labeled with its distance. A queue strip along the bottom shows cells leaving from the left as their neighbors join on the right. When the wave touches the goal, the shortest path traces back in gold.
Flip the DFS toggle and the same maze restyles: a single tendril probes deep along one corridor, hits a dead end, retracts, and dives down the next branch — with an explicit stack panel pushing and popping in sync.
What to watch for:
- BFS ring number = exact distance. The first wave to touch any cell got there by a shortest route — that's the property everything "fewest steps" relies on.
- Queue vs stack is the entire difference. First-in-first-out produces fair, ring-shaped exploration; last-in-first-out produces the deep probe. Same cells, same edges, same O(V + E) cost.
- Cells join the visited set the moment they enter the queue — watch that no cell ever appears in the strip twice.
- The DFS tendril reaches the goal by a visibly longer route. It finds a path; only BFS certifies the shortest.