Informed Search and A*
An informed search uses a heuristic , an estimate of the cost from a node to the goal, to decide what to expand next. Greedy best-first search follows the heuristic blindly and gives up optimality; A* corrects it by ranking nodes on , and is optimal when the heuristic is admissible (tree search) or consistent (graph search).
╌╌╌╌
An uninformed search knows only the problem definition: the start state, the actions, the goal test, and the step costs. It cannot tell a promising node from a hopeless one, so it expands the frontier by a fixed rule — shallowest first, cheapest-path first — and pays for that ignorance in nodes expanded. An informed search brings in problem-specific knowledge beyond the definition itself, and uses it to expand fewer nodes on the way to a solution.1
The knowledge arrives as a single number attached to each node.
For route-finding across Romania, the natural heuristic is the straight-line distance from a city to the destination: it is easy to compute, it correlates with actual road distance, and it can never exceed it because a straight line is the shortest path between two points. Notice what the definition does not require — cannot be read off the problem statement (you need a map with coordinates), and knowing that it is useful takes a little experience. That is the whole point: the heuristic is the channel through which extra knowledge enters the search.
This lesson develops the two informed strategies and proves the guarantees of the central one, A*. It leaves open the practical question of where good heuristics come from — relaxed problems, pattern databases, dominance — which is the subject of the companion lesson, Heuristic Functions and Memory-Bounded Search.
Best-first search
Both strategies in this lesson are instances of one scheme, best-first search: keep the frontier in a priority queue and always expand the node with the lowest value of an evaluation function , which we read as a cost estimate — small means promising. Underneath, this reuses the priority-queue graph search that uniform-cost search uses, with substituted for to order the queue. Everything below comes down to one choice: what is ?
Greedy best-first search
The most direct use of a heuristic is to trust it completely. Greedy best-first search expands the node that looks closest to the goal, ranking the frontier by the heuristic alone:
On the Romania map with and Bucharest as the goal, greedy search starting from Arad expands Sibiu first (closest of Arad's neighbours to Bucharest), then Fagaras (closest of Sibiu's), and Fagaras generates Bucharest. It reaches the goal having expanded only nodes on a single downhill run toward it — the search cost is minimal.2
But the path it returns, Arad–Sibiu–Fagaras–Bucharest, is km longer than the route through Rimnicu Vilcea and Pitesti. Greedy search is not optimal. The name is the diagnosis: at each step it grabs the node that gets closest to the goal right now, with no accounting for the cost already accumulated on the path. A short first hop toward the goal that commits you to a long detour later is invisible to a function that ignores .
Greedy tree search is also incomplete, in the same way depth-first search is. Getting from Iasi to Fagaras, the heuristic points first at Neamt (closest to Fagaras), which is a dead end; the true first move is to Vaslui, a step that is farther from the goal by the heuristic. A greedy tree search that keeps re-expanding Neamt (returned to the frontier each time Iasi is reached) loops forever. The graph-search version, which refuses to re-expand a state, is complete in finite spaces but not in infinite ones. Worst-case time and space for the tree version are with the maximum depth, though a good heuristic cuts this sharply in practice.
A* search
A* search fixes greedy search's blind spot by adding back the cost already paid. It evaluates a node by combining , the cost to reach , with , the estimated cost to get from to the goal:
Since is the actual path cost from the start to and estimates the remaining cost, estimates the cost of the cheapest solution that passes through . Ranking the frontier by therefore expands, at each step, the node that lies on the currently most promising complete path. This is more than a sensible heuristic: provided meets a mild condition, A* is both complete and optimal. The algorithm is identical to uniform-cost search except that it orders the queue by rather than alone — and uniform-cost search is just the special case , in which A* has no heuristic guidance and reduces to Dijkstra's shortest-path expansion.3
- 1input: a problem with start state , goal test, step costs , heuristic
- 2node for with
- 3frontier priority queue ordered by , containing
- 4explored empty set
- 5loop do
- 6if frontier is empty then return failure
- 7pop the node with lowest from frontier
- 8if passes the goal test then return the path to
- 9add state of to explored
- 10for each action available at do
- 11child of via , with
- 12if state of is not in explored and not in frontier then
- 13add to frontier
- 14else if reaches a frontier state at higher then
- 15replace that frontier node with
Admissibility: optimality for tree search
The condition A* needs for tree search is that be admissible.
Admissible heuristics are optimistic by nature: they always think the goal is at least as close as it really is. Because is the exact cost along the current path and , an admissible makes a lower bound on the true cost of any solution through . Straight-line distance is admissible for exactly this reason — no road is shorter than the straight line, so can never overshoot.
Here is the argument that admissibility gives optimality for tree search. Suppose a suboptimal goal node , with cost , sits on the frontier alongside a node that lies on an optimal path to the true goal , with optimal cost . Then
using admissibility for the first inequality. So has strictly smaller than , and A* expands before it would ever select . Every node on the optimal path is expanded ahead of any suboptimal goal, so the first goal A* removes from the frontier must be an optimal one.
A traced A* expansion
The figure names the -values; the trace shows how the priority queue produces them. Take the Bucharest search from Arad with , whose values (in km, straight-line to Bucharest) are , , , , , , , , and . Each row selects the lowest- frontier node and lists what it generates with , , and .
| Step | Select () | Generates: state, | Frontier by |
|---|---|---|---|
| Arad () | Sibiu ; Timisoara ; Zerind | Sibiu , Timisoara , Zerind | |
| Sibiu () | Rimnicu ; Fagaras ; Oradea | Rimnicu , Fagaras , Timisoara , Zerind , Oradea | |
| Rimnicu () | Pitesti ; Craiova | Fagaras , Pitesti , Timisoara , … | |
| Fagaras () | Bucharest | Pitesti , Timisoara , Zerind , Bucharest , … | |
| Pitesti () | Bucharest | Bucharest , Timisoara , Zerind , … | |
| Bucharest () | — goal selected | — return |
The decisive rows are and . In step a Bucharest node appears at (reached via Fagaras), but A* does not stop: Pitesti at is smaller and sits ahead of it in the queue. Expanding Pitesti in step generates a second Bucharest node at , cheaper than the first, and it jumps to the front. Only in step , when Bucharest at is selected, does A* return — Arad-Sibiu-Rimnicu-Pitesti-Bucharest, cost . The suboptimal goal sat on the frontier the whole time and was never selected, exactly as the admissibility argument promised: , so the node on the optimal path is expanded first. Note also Timisoara at and Zerind at : both have , so A* never expands either — that is pruning in action.
Consistency: optimality for graph search
For graph search, where we discard repeated states, admissibility alone is not quite enough; A* needs the slightly stronger property of consistency (also called monotonicity).
This is a form of the triangle inequality: the side from to the goal cannot exceed the sum of the other two sides, and . Every consistent heuristic is admissible (take a whole path of steps and the inequalities telescope to ), though the converse can fail; still, essentially every admissible heuristic one meets in practice is also consistent, included.
Consistency buys the key structural fact: is nondecreasing along any path. If is a successor of , then , so
with the inequality from consistency. So the sequence of nodes A* expands has nondecreasing . Combined with the graph-search rule that the first time we expand a state we have already found the cheapest path to it, this makes the first goal node A* selects an optimal solution: goal nodes have , so their equals their true cost, and any later goal is at least as expensive.
The contour picture
Nondecreasing lets us picture A* geometrically. Because never drops along a path, we can draw contours in the state space, exactly like the level curves of a topographic map: the region forms one band, a larger band containing it, and so on. A* expands the frontier in concentric bands of increasing -cost, fanning outward from the start.
Let be the cost of the optimal solution. The contour picture makes two facts immediate:
- A* expands every node with .
- A* expands no node with ; it may expand some nodes right on the goal contour before selecting a goal.
The second fact is pruning: A* safely ignores whole subtrees whose exceeds (Timisoara, a child of Arad in the Bucharest search, is never expanded) without any risk to optimality. With uniform-cost search the bands are circular around the start; a more accurate heuristic stretches them toward the goal and narrows them onto the optimal path — that narrowing is precisely the work the heuristic does. Among all algorithms of this kind that use the same heuristic, A* is optimally efficient: no such algorithm is guaranteed to expand fewer nodes, because any algorithm that skips a node with risks missing the optimal solution.
The catch is memory. Like every graph search, A* keeps all generated nodes, and for hard problems the number of nodes on the goal contour is still exponential in the solution length. A* usually exhausts memory long before it runs out of time.
A* is only as good as its heuristic — the narrower those contours, the less work it does — which raises the question its optimality proof left open: where does a good come from, and what do you do when even A*'s memory bill is too high? This continues in Heuristic Functions and Memory-Bounded Search.
Footnotes
- Russell & Norvig, Artificial Intelligence: A Modern Approach (3rd ed.), §3.5 — Informed (Heuristic) Search Strategies: best-first search as an instance of the general tree/graph search that orders the frontier by an evaluation function , with the heuristic as the channel for problem-specific knowledge. ↩
- Russell & Norvig, §3.5.1 — Greedy best-first search: ; efficient but neither optimal (the 32-km-longer Bucharest route) nor complete for tree search (the Iasi–Fagaras loop). ↩
- Russell & Norvig, §3.5.2 — A* search: ; optimality via admissibility (tree search) and consistency/monotonicity with nondecreasing and the contour argument (graph search); optimal efficiency and the memory drawback. ↩
╌╌ END ╌╌