Informed (Heuristic) Search — Greedy Best-First and A*
Heuristic functions and evaluation functions, greedy best-first search, A* search with f = g + h traced step by step, admissible and consistent heuristics and why they guarantee optimality, dominance and designing heuristics from relaxed problems (8-puzzle examples), memory-bounded variants (IDA*, weighted A*), and local search in brief.
Heuristics
Uninformed search explores blindly. Informed search uses problem-specific knowledge in a heuristic function : an estimate of the cheapest cost from node to a goal (with ). Examples: straight-line distance in route finding; misplaced tiles or Manhattan distance in the 8-puzzle.
Best-first search expands the frontier node with the lowest evaluation function :
| Algorithm | Behaviour | |
|---|---|---|
| Uniform-cost search | cost so far only (no heuristic) | |
| Greedy best-first | rushes towards the goal; fast but not optimal | |
| A* | estimated total cost of the cheapest solution through |
Greedy best-first search
Always expands the node that looks closest to the goal. It can be very fast, but ignores the cost already paid, so it is not optimal and, in infinite spaces or with tree search on graphs with cycles, not complete (it can oscillate).
A* search
import heapq
def astar(start, goal, succ, h): # succ(n) yields (neighbour, step_cost)
frontier = [(h(start), 0, start, [start])]
best_g = {start: 0}
while frontier:
f, g, n, path = heapq.heappop(frontier)
if n == goal:
return path, g
if g > best_g.get(n, float("inf")):
continue # stale queue entry
for m, c in succ(n):
g2 = g + c
if g2 < best_g.get(m, float("inf")):
best_g[m] = g2
heapq.heappush(frontier, (g2 + h(m), g2, m, path + [m]))
return None
Admissibility and consistency
| Property | Definition | Guarantees |
|---|---|---|
| Admissible | — never overestimates | A* tree search is optimal |
| Consistent (monotone) | for every successor, | A* graph search is optimal; never decreases along a path; each node is expanded at most once |
Consistent ⇒ admissible (not conversely). Most natural admissible heuristics are also consistent.
Why A* is optimal (sketch): when A* is about to expand a suboptimal goal with , some node on an optimal path is still on the frontier with (admissibility), so would be expanded first.
A* is also optimally efficient: no other optimal algorithm using the same heuristic is guaranteed to expand fewer nodes. It expands every node with .
Designing heuristics
- Relaxed problems: the exact cost of a problem with fewer restrictions is an admissible heuristic. In the 8-puzzle, letting a tile move anywhere gives misplaced tiles (); letting it move to any adjacent square gives Manhattan distance ().
- Dominance: if everywhere (both admissible), is better. of admissible heuristics is admissible and dominates each.
- Pattern databases: precomputed exact costs of sub-problems.
- Effective branching factor : the branching factor a uniform tree of depth would need to contain the expanded nodes; good heuristics have close to 1.
Memory-bounded and approximate variants
| Variant | Idea |
|---|---|
| IDA* | iterative deepening on -cost thresholds; memory |
| RBFS, SMA* | recursive / memory-bounded best-first |
| Weighted A* | , : faster, cost |
| Beam search | keep only the best nodes per level (incomplete) |
Local search in brief
When only the final state matters (scheduling, configuration, 8-queens), keep one current state and move to better neighbours: hill climbing (gets stuck in local maxima and plateaus), random restarts, simulated annealing (sometimes accept worse moves, with probability that falls as the temperature cools), and genetic algorithms.
Quick revision
Practice questions
GATE-style questions: 3 one-mark and 6 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
Directed graph with step costs (ties broken alphabetically): S→A (1), S→B (4), A→C (2), A→D (5), B→D (1), C→G (6), D→G (2). Start S, goal G. Heuristic : S 5, A 5, B 1, C 5, D 2, G 0. Graph search; goal test on expansion.
In which order does A* expand the nodes?
Directed graph with step costs (ties broken alphabetically): S→A (1), S→B (4), A→C (2), A→D (5), B→D (1), C→G (6), D→G (2). Start S, goal G. Heuristic : S 5, A 5, B 1, C 5, D 2, G 0. Graph search; goal test on expansion.
The value of of node C when A* generates it is ______.
A heuristic is admissible if, for every node ,
Which statements about heuristic search are correct (positive step costs)?
One or more options are correct.
In the 8-puzzle, the state below must reach the goal shown. The sum of Manhattan distances of the tiles (not counting the blank) is ______.
| state | goal | |||||
|---|---|---|---|---|---|---|
| 2 | 8 | 3 | 1 | 2 | 3 | |
| 1 | 6 | 4 | 8 | _ | 4 | |
| 7 | _ | 5 | 7 | 6 | 5 |
Two admissible heuristics satisfy for every node. Then
At a node, two admissible heuristics give and . The largest admissible estimate obtainable by combining them, , is ______.
A* graph search (which never re-expands a closed node) is guaranteed to return an optimal solution when the heuristic is
Weighted A* expands nodes in order of with an admissible and . If the optimal solution cost is , the cost of the solution it returns is guaranteed to be at most ______.