Informed Search
Informed Search
Search Problems and Search Trees
A search problem is an abstract model of a world that preserves the information relevant to an agent’s decisions. It consists of:
States: Representations of possible configurations of the world.
Actions: Choices available to the agent in each state.
Successor function: Specifies the state reached by an action and the action’s cost.
Start state: The state where the agent begins.
Goal test: Determines whether a state satisfies the desired condition.
A search algorithm systematically explores possible action sequences to find a path from the start state to a goal state. A search-tree node represents a path—a sequence of actions and states—not merely a state in the world. Different nodes in the tree may therefore represent different paths to the same state.
The fringe is the collection of nodes that have been generated but not yet expanded. To expand a node, the algorithm applies the successor function and adds the resulting nodes to the fringe. Search algorithms differ in how they choose the next fringe node to expand.
A path’s cumulative cost, denoted g(n) for a node n, is the sum of the costs of the actions along that path. An optimal search algorithm finds a least-cost path to a goal.
Tree Search pattern: Add the start node to the fringe; repeatedly select a fringe node, test it for the goal, and, if it is not a goal, expand it. A solution is found when a goal node is selected for expansion—not merely when it is first added to the fringe.
Many strategies can use a priority queue for the fringe. The priority assigned to each node determines the expansion order. Depth-first search can instead use a stack, and breadth-first search can use a regular queue.
Uninformed Search and Its Limitations
Uniform Cost Search (UCS) expands the fringe node with the lowest cumulative cost g(n). It does not use information about which states appear closer to a goal.
With nonnegative action costs, UCS is complete when a solution exists and finds a least-cost solution. However, it may explore broadly in every direction. In a grid, for example, it can expand almost every state that is cheaper to reach than the goal, including many states that lead away from the goal.
This motivates informed search: using an estimate of the remaining cost to guide exploration toward a goal.
Heuristics
A heuristic function, written h(n), estimates the cost of reaching a goal from node n. It is designed for a particular search problem. Heuristics can guide search toward promising states, but their usefulness depends on both their accuracy and the effort required to compute them.
A heuristic is commonly designed to be measured in the same units as the path cost. At a goal state, the remaining cost is zero, so a suitable heuristic has value zero there.
Examples of heuristic estimates
Grid navigation
For a grid in which movement is allowed only up, down, left, or right, Manhattan distance estimates the distance to a goal by adding the horizontal and vertical separations:
It ignores obstacles, so it may underestimate the actual route length. This makes it a useful estimate when the real cost is based on grid steps. Euclidean distance, the straight-line distance, is another possible estimate, but it may fit a grid with no diagonal movement less closely.
Route finding
For travel between cities, straight-line distance to the destination can serve as a heuristic if the cities’ coordinates are known. It estimates the remaining travel distance while ignoring the fact that roads may not follow a straight line.
Pancake flipping
In the pancake-flipping problem, pancakes of different sizes must be arranged with the largest at the bottom and the smallest at the top. An action places a spatula beneath some pancakes and flips the stack above it. If flipping k pancakes has cost k, then useful heuristic ideas include:
Number of misplaced pancakes: Every pancake that is out of position must be flipped at least once. This gives a lower bound on the remaining cost.
Largest out-of-place pancake: Number the pancakes by size and use the size number of the largest pancake still out of place. That pancake must be reached by a flip deep enough to include it, so the estimate reflects how far down the stack rearrangement must extend.
Correctly ordered groups: A group of pancakes already in the appropriate relative order may require less rearrangement. To turn such a measure into an estimate of distance from the goal, it must be framed so that the estimate is zero at the goal and increases as more work remains.
Different heuristics may assign different values to the same state. A larger estimate is not automatically better: the estimate must satisfy the conditions needed by the search method being used.
Greedy Best-First Search
Greedy Search selects the fringe node with the lowest heuristic value h(n). It chooses the node that appears closest to a goal, while ignoring how much cost has already been spent to reach it.
Strengths and limitations
It can reach a goal quickly when the heuristic points in the right direction.
It may find a suboptimal solution because it ignores the path cost already incurred.
It can pursue a promising-looking route even when reaching that route required an expensive action.
With a poor heuristic, it may behave like badly guided depth-first search, spending effort in the wrong region.
For example, a route-search heuristic might make a city look close to the destination even though the route to that city was costly. Greedy Search considers only the estimated remaining distance, so it may choose that route over a cheaper path that would produce a lower total cost.
The key distinction is that Greedy Search ranks nodes by h(n) alone. It seeks apparent proximity to a goal rather than the least-cost complete path.
A* Search
A Search* combines the cost already incurred with the estimated cost remaining. It ranks each node by
where:
g(n) is the cost from the start state to n.
h(n) is the estimated cost from n to a goal.
f(n) estimates the total cost of a solution path through n.
A* expands the fringe node with the smallest f(n). In this way, it combines UCS’s concern for costs already paid with Greedy Search’s use of information about the goal. With a useful heuristic, it can focus exploration more effectively than UCS while still finding an optimal solution under the appropriate conditions.
When A* may declare success
A* must wait until a goal node is removed from the fringe for expansion—sometimes described as being dequeued or popped—not merely until a goal is generated and added to the fringe.
A goal that has just been generated may not be the cheapest goal path. Another fringe node may still lead to a cheaper solution. If A* stops as soon as it enqueues a goal, it can return a suboptimal path. Waiting until a goal is selected according to the f-priority avoids this error under the algorithm’s optimality conditions.
Admissible Heuristics and A* Optimality
Let h∗(n) be the actual least cost of a path from n to a goal. A heuristic is admissible if it never overestimates that least remaining cost:
An admissible heuristic is optimistic: it may underestimate the remaining cost, but it does not claim that the goal is farther away in cost than it really is.
Examples include:
Manhattan distance in a grid when obstacles can only make the true route longer.
A pancake heuristic based on the minimum amount of flipping that must still occur.
The number of misplaced tiles in the 8-puzzle, when every misplaced tile must be moved at least once.
Admissibility does not require a heuristic to be highly accurate. The zero heuristic, h(n)=0, is admissible because it never overestimates the cost to the goal. With this heuristic, A* ranks nodes only by g(n) and behaves like Uniform Cost Search. It remains optimal, but it gains no guidance from the heuristic.
Why admissibility makes A* Tree Search optimal
Consider an optimal goal node a in the search tree and a suboptimal goal node b. Here, each node represents a particular path to a goal; multiple nodes may correspond to different paths or even different goal states.
Suppose b is on the fringe while the optimal path represented by a has not yet been completed. Then some ancestor n of a must also be on the fringe. Otherwise, the path to a would already have been expanded through to a.
Admissibility gives the key comparison:
The estimate from n cannot exceed the actual cost of completing the optimal path through a. Since a is a goal, its heuristic is zero, so f(a)=g(a). Because a is optimal and b is suboptimal, g(a)<g(b). The heuristic is also zero at b, so f(b)=g(b). Thus:
A* selects the lowest-f fringe node first, so it must expand n before b. Repeating this reasoning along the path ensures that the optimal goal node a is reached before a suboptimal goal node is selected. Therefore, A Tree Search is optimal when the heuristic is admissible*.
If the heuristic overestimates, a genuinely promising path may receive an artificially large f value and remain on the fringe too long. A* may then select a more expensive goal first.
Designing and Comparing Heuristics
Heuristic design is central to using A* effectively. A more informative heuristic often reduces the number of nodes expanded, but it may take more computation to calculate. There is a trade-off between the cost of evaluating a heuristic and the search effort it saves.
Relaxed problems
A systematic way to construct an admissible heuristic is to solve a relaxed problem: a simpler version of the original problem with fewer constraints or additional actions.
Because the relaxed problem is easier, its optimal solution cost cannot exceed the cost required in the original problem. The relaxed problem’s optimal cost is therefore an admissible estimate for the original problem.
Examples:
In a maze, removing walls creates a relaxed problem. The distance in the wall-free space can be used as a lower bound on the actual route cost.
In the 8-puzzle, allowing a tile to move directly to its destination without being constrained by other tiles creates a relaxed problem. The number of misplaced tiles is the cost in this simplified version.
A less relaxed 8-puzzle model allows each tile to move toward its destination independently, without other tiles blocking it. This leads to total Manhattan distance.
Heuristic dominance
For two admissible heuristics, h1 dominates h2 if h1 is at least as large at every node:
A dominating admissible heuristic is generally more informative because it gives a tighter lower bound while still not overestimating the true remaining cost. Some heuristics cannot be ranked this way: one may be larger at certain nodes and smaller at others.
If h1 and h2 are both admissible, then their pointwise maximum is also admissible:
This combined heuristic is at least as informative as either one individually.
The exact heuristic
The perfect heuristic would give the actual remaining optimal cost at every node, h∗(n). It would guide A* extremely effectively, but computing it generally requires solving the original problem from that node. If the exact cost were already known, the search problem would effectively have been solved. Practical heuristics aim for a useful estimate that is informative without being as costly to compute as the solution itself.
Example: The 8-Puzzle
The 8-puzzle consists of eight numbered tiles and one empty space on a 3×3 board. A state is a board configuration. An action moves a tile into the empty space, equivalently moving the empty space to an adjacent location. A common action cost is 1 per tile move.
There are 9! possible arrangements of the nine positions. The number of legal successors depends on the empty space’s location; for example, if it is in the center, four tiles can move into it.
Misplaced-tile heuristic
The heuristic counts the tiles that are not in their goal positions. Every misplaced tile must undergo at least one move, so this count is a lower bound on the remaining number of actions. It is therefore admissible.
Total Manhattan-distance heuristic
For each numbered tile, calculate the number of horizontal and vertical steps separating its current position from its goal position, then add those distances:
The empty space is not counted. Each tile must travel at least its Manhattan distance to reach its goal, so the sum is an admissible lower bound. This heuristic is more informative than simply counting misplaced tiles because it estimates how far each misplaced tile must travel, not just whether it is misplaced.
A stronger heuristic can substantially reduce the number of nodes A* expands compared with UCS. In the example discussed, UCS expanded millions of nodes for a harder instance, while A* with the misplaced-tile heuristic expanded only hundreds and the Manhattan-distance heuristic fewer still. These values illustrate the impact of heuristic quality; the exact expansion counts depend on the instance and implementation.
Graph Search
Tree Search can generate many nodes representing paths to the same state. In a cyclic state space, this can cause repeated work and rapid growth of the search tree. Graph Search avoids re-expanding states that have already been expanded.
It maintains a closed set of expanded states:
Select a node from the fringe.
If its state is already in the closed set, do not expand it again.
Otherwise, apply the successor function and add its state to the closed set.
The closed collection should be implemented as a set, so checking whether a state has already been expanded is efficient. Graph Search can save substantial time by avoiding repeated exploration of the same state.
For example, if Breadth-First Search first reaches a state in one step and later reaches it by a two-step path, expanding the state again through the longer path cannot reveal a better continuation: the future options from that state are the same, but the later path has already cost more.
Graph Search does not necessarily lose completeness merely by skipping repeated states: the skipped state has already been reached and its successors have been explored. However, optimality requires additional care. With some heuristics, a state may first be expanded through a more costly path and later be reached through a cheaper one. A basic closed-set implementation will skip the later route, potentially preventing the search from finding the optimal solution.
Consistent Heuristics and A* Graph Search
A heuristic is consistent if, for every transition from state n to successor n′, it satisfies
where c(n,n′) is the cost of moving from n to n′.
Consistency requires heuristic estimates to agree locally across every step. It is stronger than admissibility: it ensures that the estimate at a state cannot be larger than the cost of taking one step and then using the successor’s estimate.
Why consistency matters
If h is consistent, the A* evaluation value cannot decrease along a path. Since g(n′)=g(n)+c(n,n′), consistency implies:
Equivalently, f(n)≤f(n′). Thus, as A* follows a path, its f values stay the same or increase.
This property ensures that when A* first expands a state, it has reached that state along a least-cost path. The closed set can therefore safely prevent that state from being expanded again. Under the standard assumptions of A* search, A Graph Search is optimal with a consistent heuristic*. When the goal is expanded, its path is optimal.
For example, if one state is estimated to be 4 cost units from the goal, a successor one step away should not be estimated as only 1 unit away if the transition cost is 1: that would violate consistency. A consistent estimate must satisfy the one-step bound.
Key Comparisons
Uniform Cost Search
Expands by cumulative cost g(n).
Does not use a distance estimate to the goal.
Is optimal with nonnegative action costs, but may expand many irrelevant states.
Greedy Search
Expands by heuristic estimate h(n) alone.
Can find a solution quickly when the heuristic is useful.
Can return a suboptimal solution because it ignores the cost already incurred.
A* Search
Expands by f(n)=g(n)+h(n).
Balances cost so far with estimated cost remaining.
Is optimal for Tree Search with an admissible heuristic.
Is optimal for Graph Search with a consistent heuristic.
A*’s practical effectiveness depends strongly on heuristic design: a useful heuristic guides the search toward the goal while preserving the lower-bound property needed for optimality.

Ask anything
We've read this whole study set, so questions about it get the best answers.