Visual walkthrough — A - algorithm — heuristic, admissibility, consistency — important for GNC
What this page proves, in one breath: we will build — from nothing — the single most important fact about A*: if your guess never overpromises, the first goal A* pulls out of its queue is guaranteed to be the shortest possible. We prove it in pictures, one idea per figure, then show exactly where it breaks when the guess lies.
Everything here rests on the parent note's three functions. We restate them once, in plain words, before we use a single symbol.
The three quantities (nothing assumed). Picture a road network of nodes (places, drawn as dots) joined by edges (roads, drawn as lines). Each edge has a cost — how expensive it is to travel it (distance, time, fuel). We require every edge cost to be (no road pays you to walk it); this is the standard setting and it is what makes the estimates below sensible.
- = the real cost of the cheapest road we have actually found from the start to the node . It is money already spent.
- = a guess of the remaining cost from onward to the goal. It is a peek, not a fact.
- = ==guessed total cost of a whole trip that passes through ==. Spent + still-owed.
A* always pulls out (we say "pops") the frontier node with the smallest . The frontier — the "open list" — is the ring of dots we have reached but not yet expanded.
We also need one word: = the true cheapest remaining cost from to the goal. We never know it while running (that is why we need a guess ), but it exists, and our whole proof compares against it. Because every edge cost is , this true remaining cost is itself never negative: .
This walkthrough needs only admissibility (). It does not need the triangle inequality, Bellman's principle, or the stronger property called consistency — those decide a different question (whether A* ever has to re-expand a closed node), covered in the parent note, not the optimality proof here.
Step 1 — Set the stage: start, goal, and the frontier
WHAT. We draw a start node , a goal node , and colour the frontier — the dots we have reached but not yet fully explored — in amber. Everything behind the frontier is "closed" (done); everything ahead is unexplored.
WHY. Every proof about A* is really a proof about the moment before a bad thing could happen. To reason about that moment we must first see the picture of the search in progress: a wavefront of amber frontier nodes sweeping from toward .
PICTURE. Look at the amber ring in the figure. Anything not yet reached lies beyond it, so any path from to that is not yet finished must cross that ring at some dot. Hold that thought — it becomes Step 3.
Step 2 — Define the enemy: a suboptimal goal
WHAT. Suppose, for contradiction, that A* is about to pop a goal node we call whose found cost is worse than optimal. Write the true best total cost as . So .
WHY this move. We use proof by contradiction: assume the disaster (popping a bad goal first) and show it forces an impossibility. If a bad goal can never be popped first, then the first goal popped is optimal — which is exactly what we want.
- — the real cost of the path A* has for this goal.
- — the length of the genuinely shortest route.
- The strict is the assumption "this goal is worse than optimal."
PICTURE. The figure shows two goal-coloured dots: the true optimal goal at cost (cyan) and the impostor at a bigger cost (amber). We will prove A* can't reach for the amber one first.
Step 3 — There is always a good node waiting on the frontier
WHAT. Take the true optimal path from to . It has not been fully explored yet (we haven't popped a goal). By Step 1's picture, it must cross the amber frontier at some node — call it . This sits on an optimal path and is on the open list.
WHY. We need a concrete node whose -value we can bound. The optimal path is the perfect place to find one, because along an optimal path the numbers behave beautifully (Step 4).
PICTURE. Follow the cyan optimal path in the figure; where it pierces the amber ring, that dot is . It is the "champion" waiting in the queue.
Step 4 — The champion's can never exceed
WHAT. We compute and squeeze it below .
Term by term:
- — because lies on the optimal path, this is the optimal cost of getting to .
- — this is admissibility: the guess never overpromises. This inequality is the entire engine of the proof.
- — spent-to- plus true-remaining-from-, along the optimal path, is exactly the optimal total.
WHY the tool "admissibility" and not something else? We needed to turn a guess into a fact we can compare with . The only bridge from guess to truth is the promise " never exceeds ." That single inequality is precisely what lets us replace by and collapse to .
PICTURE. The bar chart stacks (cyan) and (amber); a dashed line marks . The amber part is capped at — it can only sit below the true remaining cost, so the whole bar stays at or under .
Step 5 — The impostor's is strictly larger
WHAT. For any goal node, the remaining trip is zero, so . Therefore
- — you are already at the goal; nothing remains to estimate.
- — this is our Step 2 assumption.
Chaining Step 4 and Step 5:
WHY. Now both key nodes are expressed as pure -values on the same scale. A* only ever cares about , so we have set up a direct comparison.
PICTURE. Two stacked bars side by side: the champion (short, ) and the impostor (tall, ). The dashed line sits cleanly between them.
Step 6 — The contradiction: A* pops the smaller first
WHAT. A* is defined to pop the smallest on the frontier. Since and both are on the open list, A* must pop before it ever reaches . So A* cannot pop the suboptimal first. Contradiction with Step 2. ∎
WHY it matters. The disaster was impossible. Therefore the first goal A* removes from the queue is optimal. Admissibility is not a nice-to-have — it is exactly the hinge that makes this contradiction fire.
PICTURE. A min-heap (see Priority Queue / Min-Heap) with at the top (smallest ) and buried below. The pop-arrow grabs first.
Step 7 — Degenerate case: what if everywhere?
WHAT. Set the guess to zero for every node. Then .
WHY show it. A reader must never meet a case we skipped. Because (Step 0's non-negative-cost assumption), the choice satisfies , so it is admissible — the whole proof above still holds. A* is still optimal; it has simply lost its sense of direction and expands outward evenly. That is precisely Dijkstra's Algorithm. (Note how the non-negativity of is exactly what makes true here — without it, this case would not go through.)
PICTURE. Two frontiers overlaid: a fat circular ripple (, Dijkstra) versus a narrow cone ( good guess) both reaching . Same shortest answer, wildly different amount of exploration.
Step 8 — Degenerate case: what if lies (inadmissible)?
WHAT. Now let overpromise: for some node. Take the parent's Example 2. Path costs (the true optimum). A direct edge costs . Set the bad guess while the truth is .
- Because , A* pops the direct goal first and returns 2.5 — missing the true optimum 2.
WHY. This shows where Step 4 fails: the line "" is gone, so we can no longer squeeze below . The champion now looks expensive and gets buried. Overestimation is not a small sin — it silently breaks optimality. (If you want speed and can tolerate a bounded error, that is the deliberate trade of Weighted A* and Bounded Suboptimality.)
PICTURE. The bad- bar for towers over the line — its amber () has smashed through the cap . Beside it, the cheaper-looking direct goal wins the pop.
The one-picture summary
WHAT. One figure compresses the entire argument: the amber frontier, the cyan optimal path piercing it at champion , the two stacked-bar -values with the dashed line separating (safe) from (too tall), and the min-heap popping first. Admissibility is the single arrow labelled "" that keeps the champion's bar under the line.
Recall Feynman retelling of the whole walkthrough
You're in a maze, walking from to the exit . At every step you look at the ring of places you've reached but not yet explored — that's the amber frontier — and you always go poke at the place whose guessed total trip (steps already walked plus peek-to-exit) is smallest.
Now here's the trick. The real shortest path out of the maze must cross that amber ring somewhere — call that spot . Since your peek at never overpromises, your guessed total there is never more than the real shortest length . Meanwhile any bad exit you might stumble on early costs more than , and once you're standing on an exit your peek is zero, so its total is just its (too-big) walked cost. So the good spot always has a smaller number than the bad exit — and since you always grab the smallest number first, you can never grab a bad exit before walking through toward the real one.
That's the whole magic: as long as your peek never overpromises (and never claims less than zero), the first exit you reach is the shortest one. Peek zero everywhere → you're Dijkstra, still correct, just slow. Peek that lies too rosy → the guarantee shatters and you can walk out a longer way without noticing.
Prerequisite threads actually used here: Heuristic Functions (what is), Priority Queue / Min-Heap (how "pop the smallest " is implemented), Dijkstra's Algorithm (the special case), and Greedy Best-First Search (the -ignored contrast). The stronger consistency property, and its link to the Triangle Inequality and Bellman Optimality, is not needed for this optimality proof — it governs the separate "no re-expansion" guarantee handled in the parent note and in GNC Path Planning.