← chapter

A* search

Dijkstra with a sense of direction. Order the frontier by f = g + h: cost-so-far + estimate-to-go.

The one extra term

Watch the frontier reach for the goal

Purple = start · red = goal · blue = open · grey = closed · green = path. The search bends around walls but strains toward the far corner.

Same path, a fraction of the work

3600 cells: Dijkstra expands ~3200 (the whole grid), A* ~290 → 11× fewer. Same optimal path.

The catch: admissibility

Takeaway

Beat a general algorithm by injecting domain knowledge it can't use — here, geometry. Dijkstra optimal among the goal-blind; A* optimal among those who know h. Next: minimum spanning trees — Prim is this same heap traversal, one word changed.