Z

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 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.