A* is a best-first search that expands the node with the lowest
f = g + h — the cost-so-far (g) plus an admissible heuristic
estimate to the goal (h). With an admissible heuristic it is guaranteed to
find the optimal path while exploring far fewer nodes than uninformed search.
Dijkstra is the special case where h = 0 — a uniform-cost
search that radiates outward equally in every direction. It is optimal but explores every
node cheaper than the goal, which is why it visits so many more cells.
Why the heuristic matters: h steers the search toward the
goal, pruning the half of the search space Dijkstra wastes exploring away from it. A
bigger (but still admissible) heuristic prunes more without sacrificing optimality.
Heat map colors each visited cell by its g score (distance
from the start) — cool blue is near the start, warm orange is far.
Frontier (dashed, pulsing) marks cells currently in the open set — discovered but not yet committed — showing the live edge of the search.