AI Notes
Complete tutorial on informed search strategies in artificial intelligence. Learn greedy search, best-first, A*, heuristic functions. BTech notes 2024.
What is Informed Search?
Informed search strategies use domain-specific knowledge—encoded as heuristic functions—to guide the exploration of the search space toward the goal. Unlike uninformed (blind) search that expands nodes without preference, informed search prioritizes nodes that appear more promising, often dramatically reducing the number of nodes explored.
The key insight is simple: if you have a way to estimate how far a node is from the goal, you can expand closer-looking nodes first. This estimate is called a heuristic function h(n), and the quality of this function determines how efficiently the search proceeds.
Informed search encompasses several algorithms: Greedy Best-First Search, A* Search, IDA* (Iterative Deepening A*), Recursive Best-First Search (RBFS), and Simplified Memory-Bounded A* (SMA*). The most important are Greedy Best-First Search and A*, which we'll study in depth.
Heuristic Functions
A heuristic function h(n) estimates the cost from node n to the nearest goal state. It encodes problem-specific knowledge that the search algorithm itself cannot derive from the graph structure alone.
Properties of Good Heuristics
Admissibility: h(n) ≤ h*(n) for all n, where h*(n) is the true optimal cost to the goal. An admissible heuristic never overestimates. This property guarantees optimality for A*.
Consistency (Monotonicity): h(n) ≤ cost(n, n') + h(n') for every successor n' of n. Consistent heuristics are always admissible, and they ensure A* never re-expands nodes.
Dominance: Heuristic h₂ dominates h₁ if h₂(n) ≥ h₁(n) for all n (both admissible). A dominant heuristic is always more efficient—it expands fewer nodes.
Example: 8-Puzzle Heuristics
Consider the 8-puzzle (sliding tiles):
| Current State | Goal State: |
| Tiles 5, 6, 8 are wrong | h₁ = 3 |
| Tile 5 | |1-2| + |2-1| = 2 |
| Tile 6 | |1-2| + |2-2| = 1 (Wait, let me recalculate) |
| Tile 5 at (1,2), goal (1,1) | distance = 1 |
| Tile 6 at (0,2), goal (1,2) | distance = 1 |
| Tile 8 at (2,2), goal (2,1) | distance = 1 |
Manhattan distance dominates misplaced tiles: h₂(n) ≥ h₁(n) for all states. In practice, h₂ explores far fewer nodes.
Greedy Best-First Search
Greedy Best-First Search (GBFS) expands the node with the lowest heuristic value h(n). It ignores the cost already paid to reach the node—only looking at estimated remaining cost.
Algorithm
function GBFS(problem, h):
frontier ← PriorityQueue ordered by h(n)
frontier.insert(initial_state)
explored ← empty set
while frontier is not empty:
node ← frontier.pop_min() // lowest h(n)
if node is goal: return solution
explored.add(node)
for each child of node:
if child not in explored and not in frontier:
frontier.insert(child)
return failureWorked Example
Graph with heuristic values (straight-line distance to goal G):
| Nodes | S(h=7), A(h=6), B(h=2), C(h=5), D(h=1), G(h=0) |
| Edges: S | A(cost=1), S→C(cost=3), A→B(cost=4), C→D(cost=2), B→G(cost=5), D→G(cost=4) |
| Step 1 | Frontier = {S(h=7)} |
| Expand S | children A(h=6), C(h=5) |
| Step 2 | Frontier = {C(h=5), A(h=6)} |
| Expand C (lowest h) | child D(h=1) |
| Step 3 | Frontier = {D(h=1), A(h=6)} |
| Expand D | child G(h=0) |
| Step 4: G found! Path: S | C→D→G, cost = 3+2+4 = 9 |
| But optimal path: S | A→B→G, cost = 1+4+5 = 10... actually S→C→D→G = 9 IS better here. |
Properties
- Complete: No (can loop without graph-search). With explored set: Yes in finite spaces.
- Optimal: No (ignores path cost g(n))
- Time: O(b^m) worst case, but good heuristics reduce this dramatically
- Space: O(b^m) — stores entire frontier
GBFS is fast but suboptimal. It's the "greedy" approach—looks locally best but may miss globally optimal paths.
A* Search
A* combines the actual cost to reach a node g(n) with the heuristic estimate h(n):
f(n) = g(n) + h(n)
This evaluation function estimates the total cost of the cheapest solution through node n. A* expands nodes in order of increasing f(n).
Why A* is Optimal
With an admissible heuristic, A* never expands a node whose f-value exceeds the optimal solution cost C*. Any goal node with g(goal) > C* will have f(goal) > C* and won't be expanded before the optimal goal.
Detailed Trace
| Graph: S | A(1), S→B(4), A→C(2), A→B(2), B→G(3), C→G(5) |
| Heuristics | S=6, A=4, B=2, C=3, G=0 |
| Step 1 | Expand S: f(S) = 0+6 = 6 |
| Children | A[f=1+4=5], B[f=4+2=6] |
| Frontier | {A(5), B(6)} |
| Step 2 | Expand A: f(A) = 5 |
| Children | C[f=3+3=6], B[f=3+2=5] |
| Update B | new path cost 3 < old cost 4 |
| Frontier | {B(5), C(6)} |
| Step 3: Expand B: f(B) = 5 (via S | A→B) |
| Child | G[f=6+0=6] |
| Frontier | {C(6), G(6)} |
| Step 4 | Expand G (or C, same f): G is goal! |
| Path: S | A→B→G, cost = 1+2+3 = 6 ✓ Optimal |
IDA* (Iterative Deepening A*)
IDA* applies iterative deepening to A*. Instead of a depth limit, it uses an f-cost limit:
function IDA*(problem):
threshold ← h(initial_state)
loop:
result, min_exceeded ← depth_limited_search(root, threshold)
if result is solution: return result
if min_exceeded == ∞: return failure
threshold ← min_exceededIDA* uses O(bd) memory (like DFS) while maintaining A*'s optimality. It's the preferred algorithm when memory is limited—common in game AI where millions of states exist.
Heuristic Design Techniques
Relaxed Problems
Remove constraints from the original problem. The optimal solution to the relaxed problem is an admissible heuristic for the original.
- 8-puzzle: Remove "can't move through other tiles" → Manhattan distance
- TSP: Remove "must visit each city once" → Minimum spanning tree cost
- Route planning: Remove "must follow roads" → Straight-line distance
Pattern Databases
Pre-compute exact solution costs for subproblems and store them in a lookup table. For the 15-puzzle, solving just tiles {1,2,3,4,5,6,7,8} gives an admissible heuristic for the full puzzle.
Combining Heuristics
Given multiple admissible heuristics h₁, h₂, ..., hₖ:
- h(n) = max(h₁(n), h₂(n), ..., hₖ(n)) is admissible and dominates each individual heuristic.
Comparison: Informed vs. Uninformed
| Aspect | Uninformed | Informed |
|---|---|---|
| Knowledge | None | Heuristic h(n) |
| Speed | Slow (exhaustive) | Fast (guided) |
| Optimality | BFS/UCS: Yes | A*: Yes (admissible h) |
| Practical use | Small spaces | Real-world problems |
Key Takeaways
- Heuristic quality determines efficiency: Better heuristics = fewer expanded nodes
- Admissibility guarantees optimality for A* — always underestimate
- Greedy is fast but suboptimal — useful when any solution suffices
- **A* is the gold standard** for optimal informed search
- **IDA* saves memory** at the cost of re-expansion — preferred for large state spaces
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Informed Search Strategies - AI Algorithms.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, search, algorithms, informed, informed search strategies - ai algorithms
Related Artificial Intelligence Topics