Worked Example: A* on a Tiny Board
Imagine a tiny 5 by 5 grid. Our source pin S is at the top-left corner (row 0, column 0). Our target pin T is near the bottom-right (row 3, column 3). There are two obstacles: a capacitor at (row 2, column 1) and another at (row 1, column 2). The autorouter can only move up, down, left, or right — one cell per step. Using Manhattan distance for the h-guess.
Step 1: S enters the open bag. Its g is 0 (we haven't moved yet). Its h is 6 (Manhattan distance from (0,0) to (3,3) is 3 horizontal + 3 vertical). Its f is 0+6 = 6.
Step 2: S is the only thing in the open bag, so we pull it out and close it. Its neighbors are (1,0) going right and (0,1) going down. Both are free. Both get g=1 (one step from S), h=5 (5 steps to T), f=6. They enter the open bag.
Step 3: Both have f=6, so we pick either. Say (1,0). Close it. Its right neighbor (2,0) gets g=2, h=4, f=6. Its down neighbor (1,1) gets g=2, h=4, f=6.
Step 4-7: The frontier marches rightward along row 0, then downward, always keeping f=6. The obstacles at (2,1) and (1,2) are blocked, so A* routes around them — specifically, it goes all the way to the right edge (col 3) then straight down.
Step 8: From (3,2), the down neighbor is (3,3) — that's T! g=6, h=0 (we're here!), f=6. T enters the closed bag. We trace backward: (3,3) came from (3,2), which came from (3,1), from (3,0), from (2,0), from (1,0), from (0,0).
Result: Path = (0,0) → (1,0) → (2,0) → (3,0) → (3,1) → (3,2) → (3,3). Length = 6 steps. Only 8 cells were ever investigated. A* went straight to the goal instead of wandering all over the board — the heuristic guided it along the border, avoiding the obstacles perfectly.