Dijkstra vs A*
Dijkstra vs A* compared — heuristics, speed, optimality and use cases, with interactive pathfinding visualizers.
Dijkstra finds shortest paths from a source to every node; A* adds a heuristic that aims at a single goal, exploring far fewer nodes. A* with a good heuristic is Dijkstra, only smarter about direction.
Dijkstra vs A* at a glance
| Dijkstra | A* | |
|---|---|---|
| Heuristic | None | Yes (estimate to goal) |
| Target | All nodes | One goal |
| Nodes explored | More | Fewer |
| Optimal | Yes | Yes (admissible heuristic) |
When to use Dijkstra
Use Dijkstra for shortest paths to all nodes or when no good heuristic exists.
When to use A*
Use A* for point-to-point pathfinding where you can estimate distance to the goal.
Tools for Dijkstra & A*
Dijkstra's Algorithm Visualizer
Interactive Dijkstra pathfinding on a grid — draw walls, move start/goal, generate mazes, step through the search. Runs in your browser.
Open toolA* Pathfinding Visualizer
Interactive A* pathfinding on a grid with a Manhattan heuristic — draw walls, move start/goal, generate mazes, step through the search. Runs in your browser.
Open toolBreadth-First Search (BFS) Visualizer
Interactive breadth-first search on a grid — draw walls, move start/goal, generate mazes, step through the level-by-level expansion. Runs in your browser.
Open toolMaze Generator
Animated maze generator using recursive division — step through the wall carving, adjust speed, regenerate. Pairs with the pathfinding visualizers. Runs in your browser.
Open toolDijkstra vs A*
Is A* always faster than Dijkstra?
For single-goal searches with a good heuristic, yes — A* explores fewer nodes. With a zero heuristic A* becomes Dijkstra, so it is never asymptotically worse for point-to-point search.