Breadth-first search
BFS takes the oldest cell from a queue and explores outward one layer at a time. On the visualizer’s four-direction grid, every move costs one step, so breadth-first search targets a shortest path by step count.
Hamza Memon’s C++ and SFML pathfinding visualizer shows how four search algorithms explore an editable maze, one cell at a time.
Read the C++ implementationBFS takes the oldest cell from a queue and explores outward one layer at a time. On the visualizer’s four-direction grid, every move costs one step, so breadth-first search targets a shortest path by step count.
DFS uses a stack to explore the latest branch first. The first path it finds can be longer than a path found by breadth-first search.
Dijkstra’s priority queue takes the cell with the lowest known cost from the start. In this app each move costs one, so it targets the same minimum number of steps as BFS even when the explored order differs.
A* orders cells by cost from the start plus an estimate of the remaining distance. This app uses Manhattan distance, the sum of the horizontal and vertical gaps to the goal.
Press S and click the start cell. Press E and click the destination, then use W to switch to wall mode and draw an obstacle. Press 1 for BFS and Space to run it. Press C to clear the search path while keeping the maze, then select A* with 4 and run the same grid again. Compare which cells are visited and where the final route goes.
The app illustrates search order on an equal-cost grid. The animation is for learning. Its playback time is not a benchmark for algorithm speed.