A* Search Algorithm: A Complete Solved Numerical Example
Scenario: Autonomous Drone Delivery Pathfinding
The Objective: Determine the most efficient delivery route for an autonomous drone from the starting facility (S) to its final destination (G) by balancing known flight costs against estimated remaining distances.
Core Mechanics▼
- The Master Equation : Always expand the node with the lowest total score. It combines the exact cost traveled so far with the estimated cost to finish .
- Never Overestimate (Admissibility): To guarantee the shortest path, your heuristic must be optimistic. It can guess lower than the true remaining cost, but never higher.
- Open vs. Closed Lists: Discovered paths wait in the Open List. Once a node is expanded as the cheapest option, it locks into the Closed List and is never evaluated again.
- The Goal Test Trap: A* only claims victory when the goal is popped from the Open List, not when it is first discovered. This prevents you from accidentally accepting a fast but expensive path!
Step 1: Initial Map Configuration
Before we begin evaluating, here is the full structure of the spatial graph and heuristic values. The algorithm balances both the exact edge costs and the estimated heuristic distances to find the optimal path.
Step 2: Step-by-Step Resolution Trace
Watch the algorithm evaluate scores, manage the Open and Closed lists, and aggressively prune sub-optimal paths.
Evaluating Node: S
Open List
[ S(14) ]
Closed List
[ ]
Evaluating Neighbors
Evaluating Node: SB
Open List
[ SB(15), SA(15) ]
Closed List
[ S(14) ]
Evaluating Neighbors
Evaluating Node: SBD
Open List
[ SBD(15), SA(15) ]
Closed List
[ S(14), SB(15) ]
Evaluating Neighbors
Evaluating Node: SA
Open List
[ SA(15), SBDG(16) ]
Closed List
[ S(14), SB(15), SBD(15) ]
Evaluating Neighbors
Evaluating Node: SBDG
Open List
[ SBDG(16), SAC(16) ]
Closed List
[ S(14), SB(15), SBD(15), SA(15) ]
Evaluating Neighbors
Goal Reached: SBDG
Goal FoundOpen List
[ SAC(16) ]
Closed List
[ S(14), SB(15), SBD(15), SA(15), SBDG(16) ]
Step 3: Final Optimal Path
Optimal Path Reached
Final Takeaway
Notice the algorithm's discipline at Step 4! Even though SBDG(16) is right next to the goal, A* pauses to explore SA(15) strictly because 15 is less than 16. During this detour, it intelligently rejects the A→B path because B is already in the Closed List, proving we found a cheaper way there earlier.