A* and Dijkstra return the same path, so the payoff is in the work saved. Today you count how many cells each search expands and pin the exact numbers that prove A* explores strictly less of the grid.
Count expanded cells in each search and show A* expands strictly fewer than Dijkstra.
Same path, same cost, so where is A*’s advantage? In the number of cells it touches. Count every cell each search finalizes, pops off the heap and expands its neighbors, and the difference is stark: on this grid Dijkstra finalizes 12 cells, while A* finalizes only 8. The heuristic steered A* along the corridor toward the goal and kept it from wandering into the far corners Dijkstra dutifully explored.
That gap is the entire reason A* exists, and it widens as maps grow. The instrument is simple, a counter that ticks each time a cell is finalized, but pinning the exact numbers turns a vague “A* is faster” into a checkable fact: strictly fewer expansions for an identical optimal path. This only holds because the heuristic is admissible and the search is otherwise Dijkstra. The next lesson shows what breaks when the heuristic cheats and claims the goal is farther than it really is.
// add a counter to the shared search loop:// when a popped cell is finalized (passes the visited guard) and is// NOT the goal, increment expanded.// expose it, e.g. return (path, cost, expanded) or a small Stats value.// run both Dijkstra (h = 0) and A* (h = Manhattan) on the same grid.