How to use the Pathfinding Visualizer
- 1. Draw on the gridDrag to add walls or weights; move the start and end.
- 2. Pick an algorithmOptionally allow diagonal moves.
- 3. Find the pathWatch the search spread, then see the path and the stats.
How the algorithms differ
- Breadth-first search spreads out evenly in all directions. It finds the fewest-step path, but ignores weights.
- Dijkstra always expands the cheapest cell found so far, so it finds the cheapest path even through weighted cells (cost 5 here).
- A* adds a heuristic, the straight-line grid distance to the goal, to Dijkstra's cost. It heads towards the target and explores far fewer cells while still finding the shortest path, because the heuristic never overestimates.
- Greedy best-first uses only the heuristic. It's very fast but can be fooled into long detours.
- Depth-first search follows one direction as far as possible. It finds a path, usually a long winding one.
A* and Dijkstra power route planning in maps and character movement in games.
Worked example
On the empty 15 × 25 grid, the start is at row 8, column 4 and the end at row 8, column 22. Run BFS and it explores a large diamond of cells before reaching the end; the path is 18 steps. Run A* on the same grid and it finds an 18-step path too, exploring only a narrow band of cells along the way.
Now press Random maze and compare again. A* and Dijkstra still find the shortest path, while greedy best-first may explore fewer cells but come back with a longer path, and DFS wanders. Add weighted cells across the direct route: Dijkstra and A* will go around them when that's cheaper, while BFS walks straight through, because it counts steps, not cost.
Keyboard users can Tab into the grid, move with the arrow keys and press Space to toggle a wall.
Frequently asked questions
Why does A* explore fewer cells than Dijkstra?
Its heuristic steers it towards the goal, so it skips cells that clearly lead away. With a heuristic of 0 it behaves exactly like Dijkstra.
Is diagonal movement allowed?
Tick the box to allow 8 directions. The path then can't cut across the corner of a wall.
Is the maze random each time?
Yes, each press makes a new maze with a recursive back-tracking generator.
Is the pathfinding visualizer free to use?
Yes, the pathfinding visualizer is free and costs nothing. Finding your first path shows a short form for your name and WhatsApp number one time; once that's done, this tool and every other Uncodemy tool open with no form.