Informed Heuristic Search (A* & AO*)
The core foundation of AI pathfinding and problem solving. Step-by-step verified derivations for the 8-Puzzle Problem using Manhattan Distance, Robot Grid Navigation, Priority Queue traces, and AO* search on And-Or trees.
01. Intuition & Concept Contrast
Uninformed search (BFS, DFS) blindly explores states without knowing whether a path leads toward the goal. Informed heuristic search uses domain knowledge $h(n)$ to steer search toward promising directions.
Uniform-Cost vs Greedy vs A*
Uniform-Cost Search ($f = g$): Looks only backward at cost incurred so far. Optimal and complete, but explores blindly in all directions.
Greedy Best-First ($f = h$): Looks only forward toward the goal. Very fast, but vulnerable to false leads and non-optimal paths.
A* Search ($f = g + h$): Perfectly balances past cost $g(n)$ and estimated future cost $h(n)$. Guaranteed to find the optimal shortest path if $h(n)$ is admissible.
OR Graph (A*) vs AND-OR Graph (AO*)
Standard OR Graph (A*): A branch represents alternative single choices (e.g., Robot goes Left OR Right). The solution is a single sequential path from Start to Goal.
AND-OR Graph (AO*): Used for problem reduction (divide-and-conquer). An AND branch requires solving all sub-problems simultaneously. The solution is a sub-tree.
02. A* Evaluation Function & Heuristic Properties
1. Heuristic Admissibility
A heuristic $h(n)$ is **admissible** if it never overestimates the true minimal cost $h^*(n)$ required to reach the goal:
$$0 \le h(n) \le h^*(n), \quad \forall n$$Theorem: Tree-search A* using an admissible heuristic is guaranteed to be **complete and optimal**.
2. Heuristic Consistency (Monotonicity)
A heuristic is **consistent (monotonic)** if for every node $n$ and every successor $n'$ generated by action $a$ with step cost $c(n, a, n')$:
$$h(n) \le c(n, a, n') + h(n') \implies f(n) \le f(n')$$This triangle inequality ensures that $f(n)$ never decreases along any path. Graph-search A* with a consistent heuristic never needs to re-open closed nodes.
3. Standard Heuristics for the 8-Puzzle Problem:
- $h_1(n)$ (Misplaced Tiles): Counts number of numbered tiles not in their goal position. Admissible because each tile must move at least once ($h_1 \le h^*$).
- $h_2(n)$ (Manhattan Distance): Sum of horizontal and vertical distances of all tiles from their goal slots: $$h_2(n) = \sum_{i=1}^8 \left( |x_i - x_i^{\text{goal}}| + |y_i - y_i^{\text{goal}}| \right)$$ Admissible because tiles move 1 square at a time and cannot hop. $h_2(n)$ dominates $h_1(n)$ ($h_2(n) \ge h_1(n)$), pruning more search space.
03. AO* Algorithm on AND-OR Trees
AO* operates on problem decomposition graphs. It finds the minimal cost solution tree by recursively updating cost estimates backward from leaf nodes.
1. Expand the most promising leaf node in the current partial tree.
2. Compute costs for its child branches (taking $\min$ for OR branches, and $\sum$ for AND branches).
3. Backtrack up the tree, updating costs of all ancestor nodes until the root is updated.
4. Re-mark the optimal branch pointer at each node based on the newly calculated minimum costs.
04. Notation Decoding Matrix
| Symbol | Formal Name | Plain-English Meaning | 8-Puzzle Benchmark |
|---|---|---|---|
| $g(n)$ | Path Cost | Exact moves executed from Start to current node | $g(S_0) = 0, \quad g(S_5) = 5$ |
| $h(n)$ | Heuristic Estimate | Estimated remaining moves to reach Goal state | $h(S_0) = 5, \quad h(S_{\text{Goal}}) = 0$ |
| $f(n)$ | Total Evaluation Score | Estimated total path cost passing through $n$ | $f(n) = 5$ invariant along optimal path |
| $\text{OPEN}$ | Priority Queue / Frontier | Discovered nodes awaiting expansion (sorted by $f$) | Node with smallest $f$ dequeued first |
| $\text{CLOSED}$ | Explored Set | Nodes already expanded to prevent infinite loops | Visited state configurations |
05. Repeatable Step-by-Step Solving Protocol
Write down $[r, c]$ coordinates for every numbered tile in the Goal configuration ($0$-indexed or $1$-indexed).
Calculate Manhattan distance for every tile from $1$ to $8$: $\sum (|r - r_{\text{goal}}| + |c - c_{\text{goal}}|)$. Never calculate distance for the blank space!
Determine legal blank moves (UP, DOWN, LEFT, RIGHT). For each resulting state, compute $g = g_{\text{parent}} + 1$ and updated $h$.
Expand state with lowest $f(n)$. If tied, pick the state with lower $h(n)$ (closer to goal).
List the sequence of blank moves and verify that $f(n)$ remains constant or monotonic.
06. 6 Deadly Exam Traps & Common Student Mistakes
Adding Distance for Blank Space (-)
The Manhattan heuristic is the sum of distances for numbered tiles 1 through 8 only. Adding the blank space's distance makes $h(n)$ inadmissible, violating optimality proofs.
Swapping Rows and Columns ($[r, c]$ vs $[x, y]$)
In a 2D matrix, index is $[row, column]$. A tile at Row 2, Column 1 has coords $[2, 1]$. Confusing row with $x$ causes massive arithmetic errors.
Running Greedy Best-First Instead of A*
Sorting OPEN list strictly by $h(n)$ turns A* into Greedy Best-First, which is non-optimal. Always sort by $f(n) = g(n) + h(n)$!
Squaring Distances ($\Delta x^2 + \Delta y^2$)
Squared Euclidean distance overestimates true cost when distance $> 1$, breaking admissibility. True Euclidean $\sqrt{\Delta x^2 + \Delta y^2}$ is admissible; squared is not.
Taking Minimum on AND Branches in AO*
In AO*, OR branches take $\min$, but AND branches take the SUM ($\sum$) of all connected children plus edge costs.
Terminating When Goal is Added to OPEN
A* must terminate only when the **Goal node is DEQUEUED / EXPANDED** from the priority queue, not when it is merely generated.
07. Complete University Question Bank (All Past PYQs Solved)
May 2025 · Question 3 The 8-Puzzle Problem Full A* Search Solution (20 Marks)
Solve the 8-Puzzle Problem using A* Search. Blank tile (-) can move UP, DOWN, LEFT, RIGHT.
$$\text{Initial: } \begin{bmatrix} 2 & 8 & 3 \\ 1 & 6 & 4 \\ 7 & - & 5 \end{bmatrix}, \quad \text{Goal: } \begin{bmatrix} 1 & 2 & 3 \\ 8 & - & 4 \\ 7 & 6 & 5 \end{bmatrix}$$ Blank space is at position $(2, 1)$ (Row 2, Col 1).
1. Using A* search, find optimal path from initial to goal state. (10 Marks)
2. Sequence of moves with $f(n)$ calculation taken by blank tile. (10 Marks)
Solution:
1. Goal Coordinate Mapping ($[r, c]$):
Row 0: $1:[0,0], \ 2:[0,1], \ 3:[0,2]$
Row 1: $8:[1,0], \ -:[1,1], \ 4:[1,2]$
Row 2: $7:[2,0], \ 6:[2,1], \ 5:[2,2]$
2. Initial State $S_0$ Manhattan Distance:
- Tile 1 at $[1, 0] \to \text{Goal } [0, 0]$: $|1-0| + |0-0| = \mathbf{1}$
- Tile 2 at $[0, 0] \to \text{Goal } [0, 1]$: $|0-0| + |0-1| = \mathbf{1}$
- Tile 3 at $[0, 2] \to \text{Goal } [0, 2]$: $\mathbf{0}$
- Tile 4 at $[1, 2] \to \text{Goal } [1, 2]$: $\mathbf{0}$
- Tile 5 at $[2, 2] \to \text{Goal } [2, 2]$: $\mathbf{0}$
- Tile 6 at $[1, 1] \to \text{Goal } [2, 1]$: $|1-2| + |1-1| = \mathbf{1}$
- Tile 7 at $[2, 0] \to \text{Goal } [2, 0]$: $\mathbf{0}$
- Tile 8 at $[0, 1] \to \text{Goal } [1, 0]$: $|0-1| + |1-0| = 1 + 1 = \mathbf{2}$
3. Step-by-Step Sequence of Blank Tile Moves:
Blank moves from $[2, 1]$ to $[1, 1]$. Tile 6 enters goal position $[2, 1]$!
Tiles misplaced: $1$ (dist 1), $2$ (dist 1), $8$ (dist 2). Total $h = 4$.
$$\mathbf{g(S_1) = 1, \quad h(S_1) = 4 \implies f(S_1) = 1 + 4 = 5}$$Blank moves from $[1, 1]$ to $[0, 1]$. Tile 8 moves to $[1, 1]$ (dist to $[1, 0]$ is 1).
Tiles misplaced: $1$ (dist 1), $2$ (dist 1), $8$ (dist 1). Total $h = 3$.
$$\mathbf{g(S_2) = 2, \quad h(S_2) = 3 \implies f(S_2) = 2 + 3 = 5}$$Blank moves from $[0, 1]$ to $[0, 0]$. Tile 2 enters goal position $[0, 1]$!
Tiles misplaced: $1$ (dist 1), $8$ (dist 1). Total $h = 2$.
$$\mathbf{g(S_3) = 3, \quad h(S_3) = 2 \implies f(S_3) = 3 + 2 = 5}$$Blank moves from $[0, 0]$ to $[1, 0]$. Tile 1 enters goal position $[0, 0]$!
Tiles misplaced: $8$ (dist 1). Total $h = 1$.
$$\mathbf{g(S_4) = 4, \quad h(S_4) = 1 \implies f(S_4) = 4 + 1 = 5}$$Blank moves from $[1, 0]$ to $[1, 1]$. Tile 8 enters goal position $[1, 0]$!
All 8 tiles are in their exact goal slots ($h = 0$).
$$\mathbf{g(S_{\text{Goal}}) = 5, \quad h(S_{\text{Goal}}) = 0 \implies f(S_{\text{Goal}}) = 5 + 0 = 5}$$Summary of Optimal Solution:
$$\mathbf{\text{Start} \xrightarrow{\text{UP}} S_1 \xrightarrow{\text{UP}} S_2 \xrightarrow{\text{LEFT}} S_3 \xrightarrow{\text{DOWN}} S_4 \xrightarrow{\text{RIGHT}} \text{Goal}}$$- Optimal Path Cost: $5$ moves.
- Heuristic Consistency Invariant: Notice that $f(n) = 5$ at every step. This proves the Manhattan heuristic is monotonically consistent.
Nov 2025 · Question 4.b Robot Grid Navigation A* Search Execution Trace (15 Marks)
Robot navigates from Node 0 $(0, 2)$ to Goal Node 5 $(8, 2)$.
Nodes: $0(0,2), 1(2,0), 2(2,4), 3(6,0), 4(6,4), 5(8,2)$.
Edge costs: $0\to 1: 3, \ 0\to 2: 4, \ 2\to 1: 5, \ 2\to 4: 8, \ 1\to 3: 6, \ 1\to 4: 10, \ 3\to 4: 7, \ 3\to 5: 3, \ 4\to 5: 9$.
Apply A* search using Euclidean distance heuristic. Show node expansion and $f(n) = g(n) + h(n)$. (15 Marks)
Solution:
1. Euclidean Heuristic $h(n) = \sqrt{(x_n - 8)^2 + (y_n - 2)^2}$:
- $h(0) = \sqrt{(0-8)^2 + (2-2)^2} = \sqrt{64} = \mathbf{8.00}$
- $h(1) = \sqrt{(2-8)^2 + (0-2)^2} = \sqrt{36 + 4} = \sqrt{40} \approx \mathbf{6.32}$
- $h(2) = \sqrt{(2-8)^2 + (4-2)^2} = \sqrt{36 + 4} = \sqrt{40} \approx \mathbf{6.32}$
- $h(3) = \sqrt{(6-8)^2 + (0-2)^2} = \sqrt{4 + 4} = \sqrt{8} \approx \mathbf{2.83}$
- $h(4) = \sqrt{(6-8)^2 + (4-2)^2} = \sqrt{4 + 4} = \sqrt{8} \approx \mathbf{2.83}$
- $h(5) = \sqrt{(8-8)^2 + (2-2)^2} = \mathbf{0.00}$
2. Complete Step-by-Step Priority Queue Trace:
| Step | Node Expanded | Successor | $g(n)$ | $h(n)$ | $f(n) = g + h$ | Priority Queue (OPEN) |
|---|---|---|---|---|---|---|
| 0 | - | 0 | 0 | 8.00 | 8.00 | $\{[0]: 8.00\}$ |
| 1 | 0 | 1 2 | 3 4 | 6.32 6.32 | 9.32 10.32 | $\{[1]: \mathbf{9.32}, [2]: 10.32\}$ |
| 2 | 1 | 3 4 | 3+6=9 3+10=13 | 2.83 2.83 | 11.83 15.83 | $\{[2]: \mathbf{10.32}, [3]: 11.83, [4]: 15.83\}$ |
| 3 | 2 | 4 (via 2) | 4+8=12 | 2.83 | 14.83 | $\{[3]: \mathbf{11.83}, [4]: 14.83\}$ |
| 4 | 3 | 5 (Goal) | 9+3=12 | 0.00 | 12.00 | $\{[5]: \mathbf{12.00}, [4]: 14.83\}$ |
| 5 | 5 | Goal Dequeued | 12 | 0.00 | 12.00 | Search Halts! |
Optimal Path: $\mathbf{0 \to 1 \to 3 \to 5}$
Optimal Path Cost: $g(5) = 3 + 6 + 3 = \mathbf{12}$
May 2025 · Question 7.b AO* Algorithm on AND-OR Tree (10 Marks)
Root A has AND branch to (B AND C) with edge costs 1, 1, and OR branch to D with edge cost 1.
Node B has OR branches to E (cost 1) and F (cost 1).
Node D has AND branch to (G AND H) with edge costs 1, 1.
Heuristics: $h(B)=3, h(C)=4, h(D)=5, h(E)=5, h(F)=7, h(G)=4, h(H)=4$.
Apply AO* search to find the optimal solution path. (10 Marks)
Solution:
1. Initial Root Evaluation:
- Branch 1 (AND branch to B and C): $$\text{Cost}(A \to BC) = c(A, B) + h(B) + c(A, C) + h(C) = 1 + 3 + 1 + 4 = \mathbf{9}$$
- Branch 2 (OR branch to D): $$\text{Cost}(A \to D) = c(A, D) + h(D) = 1 + 5 = \mathbf{6}$$
Since $6 < 9$, the initial best branch is $A \to D$. Expand $D$.
2. Expanding Node D (AND branch to G and H):
$$\text{Cost}(D) = c(D, G) + h(G) + c(D, H) + h(H) = 1 + 4 + 1 + 4 = \mathbf{10}$$Update ancestor node $A$: $\text{Cost}(A \to D) = c(A, D) + \text{Cost}(D) = 1 + 10 = \mathbf{11}$.
Now re-compare at Root $A$: Branch $A \to BC$ cost is $9$, whereas updated $A \to D$ is $11$.
Branch pointer switches to $(A \to BC)$! Expand $B$.
3. Expanding Node B (OR branches to E and F):
- $\text{Cost}(B \to E) = c(B, E) + h(E) = 1 + 5 = \mathbf{6}$
- $\text{Cost}(B \to F) = c(B, F) + h(F) = 1 + 7 = \mathbf{8}$
Best choice for $B$ is $E$ with cost $6$. Update $B$: $\text{Cost}(B) = \mathbf{6}$.
Update Root $A$ via $(A \to BC)$:
$$\text{Cost}(A \to BC) = c(A, B) + \text{Cost}(B) + c(A, C) + h(C) = 1 + 6 + 1 + 4 = \mathbf{12}$$4. Final Comparison & Optimal Subtree:
Comparing Root $A$ alternatives: $\text{Cost}(A \to D) = \mathbf{11}$ vs $\text{Cost}(A \to BC) = \mathbf{12}$.
The optimal solution subtree is $\mathbf{A \to D \to (G \text{ AND } H)}$ with total cost $\mathbf{11}$.
08. Interactive Offline 8-Puzzle Manhattan Calculator
Input coordinates $[r, c]$ of numbered tiles to instantly calculate Manhattan Distance and evaluate $h(n)$ for any custom puzzle state.
Goal configuration: 1:[0,0], 2:[0,1], 3:[0,2], 8:[1,0], 4:[1,2], 7:[2,0], 6:[2,1], 5:[2,2].
09. Active Recall Self-Test Quiz
10. Exam Hall Answer Sheet Presentation Checklist
Write $f(n) = g(n) + h(n)$ with $g$ defined as cost from start and $h$ as estimated cost to goal.
Write: "$h(n)$ is admissible because a tile must move at least its grid distance to reach goal, so $h(n) \le h^*(n)$."
Write down coordinate $[r, c]$ beside each number to prevent mental math mistakes during distance sums.
Always draw a table showing: Step, Node Expanded, Generated Successors, $g, h, f$, and OPEN list state.
Draw the $3 \times 3$ grid after each of the 5 blank moves, clearly indicating blank direction (UP, UP, LEFT, DOWN, RIGHT).
Explicitly point out to examiner that $f(S_0) = \dots = f(S_5) = 5$, verifying monotonic consistency.