Draw walls on the grid, then watch three search strategies find a path. BFS explores uniformly in all directions. Dijkstra follows lowest cost. A* adds a heuristic that pulls the search toward the goal.
BFS treats all edges equally, expanding one layer at a time across an unweighted graph. Dijkstra generalizes to weighted graphs by using a priority queue to always expand the lowest-cost frontier node. A* extends Dijkstra with a heuristic function h(n) that estimates the remaining distance to the goal, focusing the search and eliminating wasted exploration.
With a consistent heuristic (Manhattan distance on this grid), A* is both optimal and complete. It never overestimates, so the first path it finds is guaranteed shortest. The visited cell count shows the tradeoff: BFS explores the most, A* explores the least, Dijkstra falls between.
The colored frontier shows where the algorithm is looking next. Visited cells show where it has already been. When it reaches the goal, the shortest path lights up. Compare how many cells each algorithm visits.
Red Blob Games · Wikipedia