Dijkstra & A* Pathfinding
Draw walls, move the start and goal, and compare Dijkstra with A*. The animation shows the frontier expanding and the final shortest path.
Choose Walls, Move start, or Move goal, then click a cell. Outlined cells are the frontier; filled cells are visited; dotted cells are the final path. A* uses Manhattan distance as a heuristic, so it usually visits fewer cells than Dijkstra while returning the same shortest path.
What you are seeing
Each cell is a node. The search keeps a frontier of nodes whose shortest distance is not final yet.
Dijkstra expands the closest known node first, so it explores evenly in all directions.
A* adds a heuristic — usually straight-line distance to the goal — so it prioritizes cells that look promising.
Why it matters
Pathfinding powers maps, games, robotics, and network routing. A* is a practical example of using domain knowledge to make a general algorithm faster.
Complexity & details
Dijkstra: O((V + E) log V) with a binary heap. A*: same worst case, often much faster with a good heuristic.
Frequently asked questions
Is A* always faster than Dijkstra?+
Not always. A* is faster when the heuristic is informative and admissible. With a poor heuristic it can behave like Dijkstra or explore even more nodes.
What makes a heuristic admissible?+
A heuristic is admissible if it never overestimates the true remaining cost. That guarantee is what lets A* return an optimal path.