All Modules Heuristics Best-First A* Exercise

Informed Search & the A* Algorithm

Heuristics, greedy best-first search, and A* — the most famous search algorithm in AI.

Module 6 · Based on Russell & Norvig, AIMA Sections 3.5–3.6

Intermediate Heuristic Search ~50 min

What You'll Learn

  • Define heuristic and the evaluation function f(n) = g(n) + h(n)
  • Design and evaluate heuristics for the 8-puzzle
  • Trace hill climbing, best-first, greedy best-first and A* by hand
  • State and use the conditions for optimality: admissibility and consistency
  • Compare heuristics quantitatively using dominance and the effective branching factor

Prerequisites: Module 4 (Problem Solving & State Spaces) and Module 5 (Uninformed Search). You should be comfortable with state spaces, frontiers, and breadth-first / uniform-cost search before starting.

What is a Heuristic?

Tic-tac-toe first moves scored by the number of winning lines they leave open
The “most wins” heuristic for tic-tac-toe: score each move by how many winning lines it still leaves open (centre = 4, corner = 3, side = 2). This one rule collapses the search almost entirely. (From the course slides.)

Uninformed search treats every unexplored state as equally promising — and pays for that ignorance with exponential work. Informed search adds one crucial ingredient: knowledge about which direction looks good.

Definition

Heuristics are rules for choosing the branches in a state space that are most likely to lead to an acceptable solution. They are based on experience, intuition, or domain knowledge — the word comes from the Greek heuriskein, "to discover" (the same root as eureka!).

AI problem solvers reach for heuristics in two classic situations:

SituationWhy exact methods failExample
1. No exact solution existsThe problem statement itself is ambiguous — the available data admits several interpretations.Medical diagnosis: a set of symptoms may have many possible causes; doctors use heuristics to pick the most plausible diagnosis and tests.
2. An exact solution exists but is computationally infeasibleThe state space is so large that exhaustive search would never finish.Chess: the full game tree exists in principle, but with roughly 10120 paths no machine can enumerate it. Every strong chess program is built on heuristics.

A first heuristic: "most wins" in tic-tac-toe

Consider the first move in tic-tac-toe. Brute force says there are 9 opening moves, 9×8 replies, and so on — but by symmetry there are really only three distinct first moves: a corner, a side, or the center. Now apply a simple heuristic: move to the square through which the most winning lines pass.

Winning lines open through each square: corner │ side │ corner 3 │ 2 │ 3 ───────┼──────┼─────── ───┼───┼─── side │center│ side = 2 │ 4 │ 2 ───────┼──────┼─────── ───┼───┼─── corner │ side │ corner 3 │ 2 │ 3 center = 4 lines corner = 3 lines side = 2 lines ⇒ heuristic says: take the CENTER first.

The center sits on 4 winning lines, each corner on 3, each side square on only 2. Applied at every turn, this "most wins" heuristic collapses the symmetric 9-move opening space to 3 options, immediately picks one, and prunes so aggressively that almost no search remains. That is exactly what a good heuristic buys you: drastically less search for a small cost in evaluation.

Heuristics are fallible

A heuristic is an informed guess, not a guarantee. It uses limited information to estimate promise, so it can be wrong — it may lead the search down a suboptimal branch or even away from the goal entirely. The art of heuristic search is designing algorithms that exploit good guesses while recovering gracefully when the guess is bad. Keep that theme in mind: it is the thread that runs from hill climbing all the way to A*.

Hill Climbing (and Why It Gets Stuck)

Pseudocode of the hill-climbing search algorithm
The hill-climbing algorithm: at each step move to the best neighbour and keep no history. Simple and memory-free — but it stops dead at any local maximum. (From the course slides.)
One-dimensional state-space landscape showing global maximum, local maxima, a shoulder and a flat local maximum
The local-search picture: elevation is the objective function and the horizontal axis is the state space. Hill climbing follows the arrow uphill from the current state — but it can get trapped on a local maximum, a shoulder, or a “flat” local maximum (plateau) and never reach the global maximum. (From the course slides.)

The simplest way to use a heuristic is hill climbing: expand the current state, evaluate its children with the heuristic, and move to the best child. Repeat. Crucially, hill climbing keeps no history — no OPEN list, no record of siblings passed over — so it can never back up and recover from a bad choice.

function hill_climbing X := Start loop if X is a goal then return SUCCESS generate the children of X and evaluate each with h if no child is better than X then return FAIL // stuck: local maximum X := the best child of X // discard everything else end

The fatal weakness: local maxima

A local maximum is a state that looks better than all of its children — yet is not the goal. Hill climbing arrives there, sees no improving move, and simply halts. In the 8-puzzle it is common to reach a configuration where every single move temporarily worsens the heuristic (e.g. a tile must move out of its goal position to let another tile pass). To reach the goal you must go downhill first — and hill climbing, by design, refuses.

Two relatives of the same disease: on a plateau all children evaluate the same, so there is no gradient to follow; on a ridge the summit is reachable only by a sequence of individually unimpressive moves that the one-step lookahead never sees.

The fix is memory

Hill climbing is greedy local search: cheap on memory, fast, and easily trapped. The cure is simple — keep the states you didn't choose. If the current path sours, fall back to the best alternative seen so far. Add that history and hill climbing becomes best-first search, our next algorithm.

Best-First Search (with OPEN and CLOSED)

A hypothetical state space where each node is labelled with its heuristic value
A hypothetical state space. Each node carries its heuristic value (e.g. A-5, H-3); best-first search always expands the open node with the lowest value. The bold path is the one it follows. (From the course slides.)
Step-by-step OPEN and CLOSED lists for a best-first search
A full trace of best-first search on the space above: at each step open is re-ordered so the lowest-heuristic node is expanded next, until the solution is found. (From the course slides.)
The same state space with the open and closed sets shaded
The same search with the open and closed sets shaded, showing how the frontier advances while explored states are set aside — this history is what lets best-first recover from dead ends. (From the course slides.)

Best-first search maintains two lists. OPEN is a priority queue of generated-but-unexpanded states, ordered by heuristic merit with the best state leftmost. CLOSED records states already expanded, so we never repeat work or loop. Because every unexpanded state stays on OPEN, the algorithm can abandon a path that turns bad and jump to the most promising state anywhere in the space — it recovers from dead ends, which hill climbing cannot.

function best_first_search open := [Start]; closed := [] while open ≠ [] do remove leftmost state from open, call it X if X is a goal then return SUCCESS else generate children of X assign each child its heuristic value put X on closed discard children already on open or closed put remaining children on open re-order open by heuristic merit (best leftmost) return FAIL

A full worked trace

Here is a small hypothetical state space in the style of Luger's Figure 4.4. Each state is labeled with its heuristic value h (lower = closer to the goal, so lower is better). State O is a dead end — a trap the heuristic makes look attractive.

A(5) ┌───┼──────┐ B(4) C(4) D(6) ┌──┴──┐ ┌──┴──┐ E(5) F(5) G(4) H(3) ┌──┴──┐ O(2) P(3) │ │ dead end GOAL(0)

We run best-first search from A, always expanding the state on OPEN with the lowest h, breaking ties leftmost. Watch how the algorithm chases the false lead O, hits the dead end, and calmly falls back to P:

IterationX (expanded)ChildrenOPEN afterCLOSED after
1A(5)B(4), C(4), D(6)[B4, C4, D6][A5]
2B(4) (tie with C, leftmost wins)E(5), F(5)[C4, E5, F5, D6][B4, A5]
3C(4)G(4), H(3)[H3, G4, E5, F5, D6][C4, B4, A5]
4H(3)O(2), P(3)[O2, P3, G4, E5, F5, D6][H3, C4, B4, A5]
5O(2)none — dead end![P3, G4, E5, F5, D6][O2, H3, C4, B4, A5]
6P(3)GOAL(0)[GOAL0, G4, E5, F5, D6][P3, O2, H3, C4, B4, A5]
7GOAL(0)— goal test succeeds → SUCCESS

Solution path (recovered by following parent links back from the goal): A → C → H → P → GOAL.

The key moment is iteration 5

The heuristic lied: O(2) looked like the best state on the entire frontier, but it was a dead end. Hill climbing would have died right there. Best-first search shrugs — P(3) was still sitting on OPEN, so the search resumes from the next-best alternative as if nothing happened. Memory converts a fallible heuristic into a robust algorithm.

The Evaluation Function: f(n) = g(n) + h(n)

So far our "merit" was just the heuristic h. But a state can look close to the goal while sitting at the end of an absurdly expensive path. A properly informed evaluation should account for both the road already traveled and the road believed to remain:

f(n) = g(n) + h(n)
TermMeaningNature
g(n)The actual cost of the path from the start to n.Known exactly — we walked it.
h(n)The estimated cost of the cheapest path from n to a goal.A heuristic guess.
f(n)The estimated total cost of the cheapest solution passing through n.Part fact, part forecast.

The two extremes of this formula are algorithms you already know (or are about to meet):

Two degenerate cases

  • f(n) = h(n) only (ignore the past) → greedy best-first search: races toward whatever looks closest. Fast, but easily misled and blind to path cost.
  • f(n) = g(n) only (ignore the future) → uniform-cost search from Module 5: guaranteed optimal, but expands in all directions with no sense of where the goal is — blind.

Use both terms and you get A* — the best of both worlds, as we'll prove shortly.

Designing Heuristics: the 8-Puzzle

An 8-puzzle start state, its three successors, and the goal state
A single 8-puzzle instance: a start state, the successors reachable by sliding the blank, and the goal. We need a heuristic that estimates how far a state is from that goal. (From the course slides.)
Three heuristics computed for several 8-puzzle states
Three heuristics compared on the same states: h₁ = tiles out of place, h₂ = sum of Manhattan distances, and 2× the number of direct tile reversals. h₂ is always at least as large as h₁ — it dominates. (From the course slides.)

The 8-puzzle is the classic heuristic laboratory: simple enough to trace by hand, rich enough that heuristic quality genuinely matters. Consider this start state and goal:

START GOAL ┌───┬───┬───┐ ┌───┬───┬───┐ │ 2 │ 8 │ 3 │ │ 1 │ 2 │ 3 │ ├───┼───┼───┤ ├───┼───┼───┤ │ 1 │ 6 │ 4 │ │ 8 │ │ 4 │ ├───┼───┼───┤ ├───┼───┼───┤ │ 7 │ │ 5 │ │ 7 │ 6 │ 5 │ └───┴───┴───┘ └───┴───┴───┘

Three candidate heuristics from the classic slides, each cheaper or richer than the last:

h₁ — number of misplaced tiles

Count the tiles not in their goal position (the blank doesn't count). Checking tile by tile: 2 is at top-left but belongs top-middle (misplaced); 8 is at top-middle but belongs middle-left (misplaced); 3 is correct; 1 is at middle-left but belongs top-left (misplaced); 6 is at the center but belongs bottom-middle (misplaced); 4, 7, 5 are all correct. Four misplaced tiles → h₁ = 4.

h₂ — sum of Manhattan (city-block) distances

For each tile, count the grid moves (horizontal + vertical) from its current square to its goal square, then sum. Misplaced tiles only: tile 2 needs 1 move, tile 8 needs 2 (one down, one left), tile 1 needs 1, tile 6 needs 1. Total → h₂ = 1 + 2 + 1 + 1 = 5.

h₃ — 2 × number of direct tile reversals

A direct reversal is a pair of adjacent tiles that must swap places (each sits in the other's goal square) — expensive to fix, so weight it by 2. In our start state no two adjacent tiles are exact swaps of each other, so h₃ = 0: the heuristic can't even tell this state from the goal!

HeuristicWorking (start state above)Value
h₁ misplaced tilestiles 1, 2, 6, 8 out of place4
h₂ Manhattan distance2→1, 8→2, 1→1, 6→1 moves5
h₃ 2 × tile reversalsno adjacent pair needs a direct swap0

Adding the path cost: f = g + h₁

Now fold in g(n) = depth of the state in the search. The start's three successors (slide a tile into the blank) each have g = 1:

start (g=0, h₁=4, f=4) │ ├─ slide 6 down: 2 8 3 / 1 _ 4 / 7 6 5 g=1 h₁=3 f=4 ◀ best ├─ slide 7 right: 2 8 3 / 1 6 4 / _ 7 5 g=1 h₁=5 f=6 └─ slide 5 left: 2 8 3 / 1 6 4 / 7 5 _ g=1 h₁=5 f=6

Moving tile 6 into place drops h₁ from 4 to 3, so its f stays at 4 while the alternatives jump to 6 — the search correctly prefers real progress and correctly penalizes moves that displace already-correct tiles (7 or 5).

The heuristic designer's trade-off

A good heuristic must be cheap to compute (it's evaluated at every generated node) and informative (it should discriminate sharply between good and bad states). These pull in opposite directions: h₃ is trivially cheap but blind (it scored our scrambled state 0); a perfect heuristic h* would solve the problem outright but costs as much as the search itself. h₂ hits the sweet spot — nearly free, yet it sees more structure than h₁. Choosing that sweet spot is heuristic design.

Greedy Best-First Search

Greedy best-first search is best-first search with f(n) = h(n): always expand the node that appears closest to the goal, ignoring how much it cost to get there. Our running example for the rest of the module is AIMA's Romania route-finding problem: drive from Arad to Bucharest, minimizing road distance. The heuristic is the straight-line distance to Bucharest, hSLD — a bird can't beat a straight line, so it's a natural estimate.

hSLD: straight-line distance to Bucharest (km)
Arad366Fagaras176Mehadia241Sibiu253
Bucharest0Giurgiu77Neamt234Timisoara329
Craiova160Hirsova151Oradea380Urziceni80
Drobeta242Iasi226Pitesti100Vaslui199
Eforie161Lugoj244Rimnicu Vilcea193Zerind374

The roads we'll need (actual driving distances): Arad–Sibiu 140, Arad–Timisoara 118, Arad–Zerind 75, Sibiu–Fagaras 99, Sibiu–Rimnicu Vilcea 80, Sibiu–Oradea 151, Fagaras–Bucharest 211, Rimnicu Vilcea–Pitesti 97, Pitesti–Bucharest 101.

The greedy trace

StepExpandedFrontier (h values)Greedy choice
1Arad (366)Sibiu 253, Timisoara 329, Zerind 374Sibiu — lowest h
2Sibiu (253)Fagaras 176, Rimnicu Vilcea 193, Timisoara 329, Zerind 374, Oradea 380Fagaras — looks closest
3Fagaras (176)Bucharest 0, Rimnicu Vilcea 193, …Bucharest — goal!

Greedy finds Arad → Sibiu → Fagaras → Bucharest = 140 + 99 + 211 = 450 km after expanding only three nodes. Impressively fast — and wrong. The optimal route is Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest = 140 + 80 + 97 + 101 = 418 km. Greedy never considered Rimnicu Vilcea (h = 193) because Fagaras (h = 176) looked closer, even though the Fagaras road is much longer.

PropertyGreedy best-first
Optimal?No — ignores g(n), so a short-looking detour wins over a genuinely short road.
Complete?No (tree version) — it can oscillate forever. Classic case: from Iasi toward Fagaras, hSLD says go to Neamt first (a dead end), then back to Iasi, then Neamt again… unless repeated states are checked.
Time / SpaceO(bm) worst case (m = maximum depth), though a good heuristic often does far better in practice.

The A* Algorithm

A* (pronounced "A-star", Hart, Nilsson & Raphael, 1968) is best-first search using the full evaluation function f(n) = g(n) + h(n): expand the node with the lowest estimated total solution cost. It is the most widely known algorithm in all of AI — the engine behind GPS routing, videogame pathfinding, puzzle solvers and planners — because with one mild condition on h (next section) it is complete, optimal, and optimally efficient.

function a_star_search open := [Start] // priority queue ordered by f = g + h closed := [] while open ≠ [] do remove the state with lowest f from open, call it X if X is a goal then return the path to X // test at EXPANSION, not generation! put X on closed for each child C of X do g(C) := g(X) + cost(X, C); f(C) := g(C) + h(C) if C is on open with a higher g then update it // found a shorter path to C else if C is not on open or closed then add C to open return FAIL

Two details matter enormously. First, the goal test happens when a node is selected for expansion, not when it is generated — otherwise A* could return the first (possibly bad) route it stumbles on. Second, if a shorter path is rediscovered to a node already on OPEN, we keep the cheaper one. Both details are exactly what saves us in the trace below.

A* from Arad to Bucharest, step by step

Same map, same heuristic as before — but now every frontier entry carries f = g + h. Follow the lowest f at each step (all arithmetic shown):

StepExpanded (lowest f)Frontier after expansion, with f = g + h
1Arad
f = 0 + 366 = 366
Sibiu 140+253=393 · Timisoara 118+329=447 · Zerind 75+374=449
2Sibiu (393)Rimnicu Vilcea 220+193=413 · Fagaras 239+176=415 · Timisoara 447 · Zerind 449 · Arad 280+366=646 · Oradea 291+380=671
3Rimnicu Vilcea (413)Fagaras 415 · Pitesti 317+100=417 · Timisoara 447 · Zerind 449 · Craiova 366+160=526 · Arad 646 · Oradea 671
4Fagaras (415)Pitesti 417 · Timisoara 447 · Zerind 449 · Bucharest 450+0=450 · Craiova 526 · Arad 646 · Oradea 671
5Pitesti (417)Bucharest 418+0=418 (shorter path found — replaces the 450 entry) · Timisoara 447 · Zerind 449 · Craiova 526 · Arad 646 · Oradea 671
6Bucharest (418)Goal test succeeds → SUCCESS. Path: Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest, cost 418 km — the optimum.

Arithmetic check: g(Sibiu)=140; g(Rimnicu)=140+80=220; g(Fagaras)=140+99=239; g(Pitesti)=220+97=317; Bucharest via Fagaras g=239+211=450; Bucharest via Pitesti g=317+101=418. All f values above follow by adding hSLD.

The beautiful moment: step 4 → 5

At step 4, A* has Bucharest in hand — the same 450 km route greedy proudly returned. But A* refuses to stop, because Pitesti's f = 417 is a promise of something better than 450, and an admissible f never over-promises. One more expansion cashes in that promise: Bucharest at 418. Only when Bucharest itself has the lowest f on the frontier — meaning no remaining node could possibly beat it — does A* declare victory. That patience is precisely why A* is optimal where greedy is merely fast.

When is A* Optimal? Admissibility & Consistency

Admissible heuristics

Let h*(n) be the true cost of the cheapest path from n to a goal. A heuristic is admissible if for every node n:

h(n) ≤ h*(n)

Admissible heuristics never overestimate — they are systematically optimistic. hSLD is admissible because no road can be shorter than the straight line. Both 8-puzzle heuristics qualify too: every misplaced tile needs at least one move (h₁), and each tile needs at least its Manhattan distance in moves since one move shifts one tile one square (h₂).

Theorem

Tree-search A* with an admissible heuristic is optimal.

Proof sketch. Let C* be the optimal solution cost, and suppose a suboptimal goal G₂ appears on the frontier. Since G₂ is a goal, h(G₂) = 0, so f(G₂) = g(G₂) > C*. Meanwhile some node n on the optimal path is always on the frontier, and by admissibility f(n) = g(n) + h(n) ≤ C*. Therefore f(n) ≤ C* < f(G₂), so A* always expands n before G₂ — it can never select a suboptimal goal. This is exactly what happened in the Romania trace: Pitesti (f = 417 ≤ 418 = C*) was expanded before Bucharest-via-Fagaras (f = 450). ∎

Consistent (monotone) heuristics

A heuristic is consistent if for every node n and every successor n′ reached by action a:

h(n) ≤ c(n, a, n′) + h(n′)

This is a triangle inequality: the estimate from n can't exceed the cost of one step plus the estimate from where that step lands. Key facts:

  • Consistency ⇒ admissibility (the converse is not true, though most natural admissible heuristics happen to be consistent).
  • With a consistent h, f is non-decreasing along every path, so the first time A* expands a node it has already found the cheapest path to it — which makes graph-search A* optimal (no reopening of closed nodes needed).
  • hSLD is consistent: the straight line from n to Bucharest is never longer than the road to n′ plus the straight line from n′ (general triangle inequality of geometry).

A*'s catch: memory

A*'s Achilles heel isn't time — it's space. It keeps every generated node on OPEN or CLOSED, and on hard problems it runs out of memory long before it runs out of patience. Memory-bounded variants exist — IDA* (iterative-deepening A*) and RBFS (recursive best-first search) achieve A*-like behavior in linear space — see AIMA §3.5.5 for the details. For now, remember: if A* fits in memory, it's usually the algorithm to beat.

Comparing Heuristics: Dominance

Given two admissible heuristics, which should you use? If h₂(n) ≥ h₁(n) for every node n, we say h₂ dominates h₁. Domination translates directly into efficiency: A* expands every node with f(n) < C*, i.e. every node with h(n) < C* − g(n) — and a larger h disqualifies more nodes. So A* with h₂ never expands more nodes than A* with h₁ (up to tie-breaking). For the 8-puzzle, Manhattan distance dominates misplaced tiles, since each misplaced tile contributes at least 1 to both counts.

How much does dominance matter in practice? Here are AIMA's classic experimental averages for randomly generated 8-puzzle instances (nodes generated to find a solution at depth d):

Solution depth dIDS (uninformed)A*(h₁ misplaced)A*(h₂ Manhattan)
d = 123,644,035 nodes227 nodes73 nodes
d = 24~54,000,000,000 nodes (infeasible)39,135 nodes1,641 nodes
Effective branching factor b* (d = 12)2.781.421.24

The effective branching factor b* is the branching factor a uniform tree of depth d would need to contain the nodes actually generated — a heuristic's quality distilled into one number (1.0 would be perfect). Squeezing b* from 2.78 down to 1.24 turns a 3.6-million-node search into a 73-node stroll.

The lesson

Better heuristics mean exponentially less work. The cost of search grows like (b*)d, so even a modest improvement in the heuristic compounds at every level of depth. Rule of thumb: among admissible heuristics, always prefer the dominant one — and if you have several with no dominator, take h(n) = max(h₁(n), …, hₖ(n)), which is admissible and dominates them all.

Exercise: Run A* Yourself

Three problems, increasing in subtlety. Do each one on paper before opening the solution — tracing A* by hand once is worth ten readings.

1

Trace A* on a small graph

Run A* from S to G on the graph below. Edge labels are step costs; h values are given per node. Break f-ties by expanding the node generated earliest. Give the order of node expansions and the final path with its cost.

2 3 4 S ────── A ────── C ────── G │ │ │ │3 │4 │ B ────── D ────────────────┘ 3 4 h(S)=8 h(A)=6 h(B)=4 h(C)=3 h(D)=4 h(G)=0
StepExpandedFrontier after, with f = g + h
1S (f = 0+8 = 8)B 3+4=7 · A 2+6=8
2B (7)A 8 · D 6+4=10 (via B, g=3+3=6)
3A (8)C 5+3=8 · D 10 (path via A also gives g=2+4=6 — same cost, keep one)
4C (8)G 9+0=9 · D 10
5G (9)Goal! (D, f = 10, is never expanded.)

Expansion order: S, B, A, C, G. Final path: S → A → C → G, cost 2 + 3 + 4 = 9. Note the little drama: B looked best at first (f = 7), but its continuation through D (f = 10) could never beat the S–A–C corridor — A* explored the tempting branch, then abandoned it, exactly as designed. (Check: the alternative route S–B–D–G costs 3+3+4 = 10 > 9, so 9 is indeed optimal.)

2

Compute h₁ and h₂

For the 8-puzzle state below (same goal as in the lesson: 1 2 3 / 8 _ 4 / 7 6 5), compute h₁ (misplaced tiles) and h₂ (Manhattan distance). Which is closer to the true solution distance?

┌───┬───┬───┐ │ 2 │ 8 │ 3 │ ├───┼───┼───┤ │ 1 │ │ 4 │ ├───┼───┼───┤ │ 7 │ 6 │ 5 │ └───┴───┴───┘

h₁ = 3: tiles 2, 8 and 1 are misplaced (3, 4, 5, 6, 7 are all home).
h₂ = 4: tile 2 needs 1 move (right), tile 8 needs 2 (down + left), tile 1 needs 1 (up); 1 + 2 + 1 = 4.
The true distance is exactly 4 moves: slide 8 down (blank up), 2 left (blank …) — concretely: blank up → blank left → blank down → blank right gives 2 8 3/1 _ 42 _ 3/1 8 4_ 2 3/1 8 41 2 3/_ 8 41 2 3/8 _ 4 = goal.
So h₂ is closer — here it is exact (h₂ = h* = 4), while h₁ underestimates by 1. This is dominance made visible: h₂ ≥ h₁ everywhere, and the bigger admissible estimate steers A* more sharply.

3

Stretch the definition

(a) Is h(n) = 0 for all n admissible? What algorithm does A* become with it? (b) Is h(n) = 3 × Manhattan distance admissible for the 8-puzzle? What do you risk by using it?

(a) Yes — 0 ≤ h*(n) always, so h = 0 is (trivially) admissible; it's the ultimate optimist that knows nothing. With it, f(n) = g(n), and A* degrades into uniform-cost search: still optimal, but completely uninformed — the "g-only" extreme from the f = g + h section.

(b) No. Manhattan distance is sometimes exact (h₂ = h*, as in exercise 2), so tripling it gives 3h* > h* — an overestimate, hence inadmissible. A* with it may still find a solution, and often faster (inflated heuristics search greedily), but the optimality guarantee is lost: it can commit to a path whose true cost exceeds the optimum, because its inflated f values wrongly disqualify nodes on the optimal path. This trade — speed for a bounded loss of optimality — is exploited deliberately in "weighted A*", but it must be a choice, never an accident.

Recap & Where Next

You now know

  • Heuristics encode fallible domain knowledge to prune search (tic-tac-toe "most wins", 8-puzzle h₁/h₂).
  • Hill climbing is heuristic search without memory — and local maxima are its grave.
  • Best-first search (OPEN + CLOSED) recovers from bad guesses; greedy (f = h) is fast but suboptimal and incomplete.
  • A* (f = g + h) is complete and optimal with an admissible h (h ≤ h*); consistency extends optimality to graph search; memory is its real limit.
  • Dominance: bigger admissible heuristics expand exponentially fewer nodes (b* 2.78 → 1.24 on the 8-puzzle).

You've reached the end of the single-agent search unit, the classical core of AI problem solving: from state spaces (Module 4), through blind search (Module 5), to A*, the algorithm the rest of the field builds on. Next: Module 7 — Adversarial Search & Games, where a hostile opponent enters the picture and we meet minimax and alpha-beta pruning. Further ahead in the syllabus: knowledge representation and logic (agents that reason, not just search).

Informed Search & A*

Objectives What is a Heuristic? Hill Climbing Best-First Search f(n) = g(n) + h(n) 8-Puzzle Heuristics Greedy Best-First The A* Algorithm Admissibility Dominance Exercise Recap