Finding the Lowest-Cost Path with A* Search
Problem Setup
Scenario:Find the lowest-cost route from the start node S to the goal node G. Each connection has a travel cost, and each node has a heuristic estimate of the remaining cost to G.
Given:A weighted graph with S as the start and G as the goal. The graph provides the edge costs and heuristic values needed to calculate A*'s evaluation score, f(n) = g(n) + h(n).
Task:Apply A* step by step: track the path cost g(n), heuristic h(n), and f(n) values, choose which node to explore next, and determine the final path from S to G.
Need a quick refresher? Review A* Search theory
Search Graph
Arrows show the permitted direction of travel, edge labels show travel costs, and the values beside nodes show heuristic estimates of the remaining cost to G.
Step-by-Step Resolution
Evaluating Node: S
Open List
[ S(14) ]
Closed List
[ ]
Evaluating Neighbors
Evaluating Node: SA
Open List
[ SA(15), SB(15) ]
Closed List
[ S(14) ]
Evaluating Neighbors
Evaluating Node: SB
Open List
[ SB(15), SAC(16) ]
Closed List
[ S(14), SA(15) ]
Evaluating Neighbors
Evaluating Node: SBD
Open List
[ SBD(15), SAC(16) ]
Closed List
[ S(14), SA(15), SB(15) ]
Evaluating Neighbors
Evaluating Node: SAC
Open List
[ SAC(16), SBDG(16) ]
Closed List
[ S(14), SA(15), SB(15), SBD(15) ]
Evaluating Neighbors
Evaluating Node: SBDG
Open List
[ SBDG(16) ]
Closed List
[ S(14), SA(15), SB(15), SBD(15), SAC(16) ]
Evaluating Neighbors
Goal Reached: SBDG
Goal FoundOpen List
[ ]
Closed List
[ S(14), SA(15), SB(15), SBD(15), SAC(16), SBDG(16) ]
Final Answer
A* reaches the goal through the lowest-cost path found during the search:
Total path cost:16
The chosen route costs 16, compared with 17 for the alternative through A and C. A* reaches the cheaper route by combining the cost already travelled with the estimated remaining cost when selecting nodes to explore.
Exam Takeaway
- Compare nodes using the complete evaluation score: A* selects the open-list entry with the lowest , not necessarily the lowest path cost or heuristic alone. If scores tie, follow the tie-breaking rule given in the question.
- Keep the cheapest known path to each node: When multiple routes reach the same node, compare their values. A larger cannot improve that node's existing path when its heuristic is unchanged.
- Check when the optimality guarantee applies: For A* graph search with nonnegative edge costs and a consistent heuristic, the goal's path cost is optimal when it is selected from the open list. Discovering the goal as a neighbor does not mean the search should stop immediately.