1.
Informed vs Uninformed Search
Uninformed search: No extra knowledge, just explores blindly (like BFS, DFS).
Informed search: Uses extra knowledge (a heuristic) to guide the search, making it
more efficient.
Think of it like this:
Uninformed = searching for your house in a city without a map.
Informed = searching with a map that shows approximate distances.
• 2. Best-First Search
• This is a general approach where we always expand (explore) the
most promising node first.
• To decide which node is most promising, we use an evaluation
function:
• f(n)=some measure of how good node n is
• The node with the lowest f(n) value is expanded first (just like "lowest
cost wins").
• 3. Heuristic Function h(n)
• A heuristic is just a smart guess:
• h(n)=estimated cost from node n to the goal
• Example: If you’re in Arad and want to reach Bucharest, h(n) could be
the straight-line distance to Bucharest.
• Properties:
• h(n) is problem-specific.
• Always non-negative.
• For a goal node, h(n)=0
• What is Greedy Best-First Search?
• It always chooses the node that looks closest to the goal (according
to the heuristic).
Formula: f(n)=h(n)
• Example: Romania Map (Arad → Bucharest)
• Heuristic used: Straight-line distance (SLD) to Bucharest, called hSLD
• Starting at Arad:
• Neighbors are: Sibiu (253 km), Zerind (374 km), Timisoara (329 km).
• Sibiu has the smallest hSLD, so expand Sibiu first.
• From Sibiu:
• Next closest city to Bucharest is Fagaras (176 km).
• From Fagaras:
• Next is Bucharest (0 km) → Goal found
• So the path found is:
Arad → Sibiu → Fagaras → Bucharest
The Good
• Fast: Often finds a solution quickly.
• Memory-efficient (compared to exhaustive search).
• If the heuristic is good, it greatly reduces the search space.
The Bad
• Not Optimal: The solution may not be the shortest path.
• In our example, Arad → Sibiu → Fagaras → Bucharest is 32 km longer than
the true shortest path (via Rimnicu Vilcea → Pitesti).
• Not Complete (Tree Search): Can get stuck in loops or dead ends.
• Example: From Iasi to Fagaras, it expands Neamt first (dead end) and keeps
looping, never reaching the goal.
• Complexity
• Worst-case time and space:
• O(b^m) where
• b = branching factor,
• m= maximum depth.
• Idea of A* Search
• Problem with Greedy Best-First Search: only looks at h(n) (how close
to the goal) → fast but not always optimal.
• Problem with Uniform-Cost Search: only looks at g(n) (cost so far) →
optimal but ignores where the goal is, so it can explore too much.
• A* Search combines both.
Formula:
• f(n)=g(n)+h(n) where
• g(n) = cost so far (from start to n)
• h(n) = estimated cost to the goal
• f(n)= estimated total cost of a solution that goes through n
Think of planning a road trip:
• g(n) = how much fuel you’ve already used
• h(n) = your estimate of how much fuel is left to reach the destination
• f(n)=g(n)+h(n) your estimate of the total fuel cost for the trip
• Properties of A*
• Complete: Always finds a solution if one exists (in finite state spaces).
• Optimal: Always finds the shortest/cheapest path, if the heuristic is good.
• Example: Romania Map (Arad → Bucharest)
• Let’s compare:
• Greedy Best-First Search: Chooses based only on h(n) → quickly finds
Arad → Sibiu → Fagaras → Bucharest (not optimal).
• Uniform-Cost Search: Chooses based only on g(n) → guaranteed optimal
path, but may explore many unnecessary nodes.
• A*: Uses f(n)=g(n)+h(n) It balances both → finds the true shortest path
efficiently:
Arad → Sibiu → Rimnicu Vilcea → Pitesti → Bucharest.
• Conditions for A* Optimality
• 1. Admissibility
• Definition:
A heuristic h(n) is admissible if it never overestimates the true cost to
the goal.
Formally:
• h(n)≤h∗(n) actual cheapest cost from n to the goal.
where h∗(n) = actual cheapest cost from n to the goal.
• Why Memory-Bounded Search?
• A* is powerful, but it needs to keep all nodes in memory → often
impractical for large problems.
• To solve this, memory-bounded variants try to keep the benefits of A*
(optimality with good heuristics) while using limited memory.
• 1. Iterative Deepening A* (IDA*)
Combines A* with iterative deepening (like iterative deepening DFS).
• Instead of storing all frontier nodes, it does repeated depth-first searches with
an f-cost cutoff.
Steps:
• Start with cutoff = h(start)
• Perform a depth-first search, but only expand nodes where f(n)=g(n)
+h(n)≤cutoff.
• If the goal is not found:
• Increase cutoff to the smallest f(n) that exceeded the previous cutoff.
• Repeat the search
• 2. Recursive Best-First Search (RBFS)
• Like best-first search but uses recursion and limited memory.
• Expands the most promising node first, but if memory runs out, it “backs
up” and continues with the next best alternative.
How It Works:
• Keep track of the best alternative path’s f-cost at each level of recursion.
• If the current path looks worse than the alternative, backtrack.
• While backtracking, update the node’s f-value to the best alternative
cost, so the algorithm remembers how promising that path was.
• Example
1. Iterative Deepening A* (IDA*) – Example with Values
Suppose a delivery drone is trying to get from A (start) to G (goal).
Heuristic h(n)= estimated distance to goal.
Actual step cost between connected nodes = 1 (for simplicity)
A→B→D→G
→C→E→G
• Heuristic values:
• h(A) = 3
• h(B) = 2
• h(C) = 3
• h(D) = 1
• h(E) = 1
• h(G) = 0
• How IDA* works:
• Start cutoff = h(A) = 3.
• Expand paths where f(n)=g(n)+h(n)≤3
• At A: f(A)=0+3=3 (OK).
• Go to B: f(B)=1+2=3 (OK).
• Go to D: f(D)=2+1=3 (OK).
• Go to G: f(G)=3+0=3 → Goal found
The drone finds the optimal path A→B→D→G without exploring unnecessary paths.
2. Recursive Best-First Search (RBFS) – Example with Values
Imagine a rescue robot navigating corridors.
S (start)
├── A (f=6)
│ └── Goal (f=8)
└── B (f=5)
└── Goal (f=7)
• RBFS works:
• At S: compare child nodes.
• A has f=6, B has f=5 → expand B first (better option).
• At B: child Goal has f=7.
• Compare alternative path A (f=6) with current path’s best (f=7).
• Since 6 < 7, backtrack to A (because A looks more promising).
• At A: Goal has f=8.
• Now compare:
• Path through A = 8
• Alternative path (B’s Goal) = 7
• So RBFS backtracks and chooses B’s path.
• The robot ends up with S → B → Goal (optimal, cost=7).
HEURISTIC FUNCTIONS
• What is the 8-puzzle?
• The 8-puzzle consists of a 3×3 grid with 8 numbered tiles (1–8) and
one empty space. The goal is to slide tiles horizontally or vertically
into the empty space until the tiles reach a specific goal configuration:
• Branching factor
• The branching factor is the average number of possible moves from
any position.
• In the 8-puzzle:
• Empty tile in corner → 2 moves possible
• Empty tile on edge → 3 moves possible
• Empty tile in middle → 4 moves possible
• So the average branching factor ≈ 3.
• The average solution cost for a randomly generated 8-puzzle instance
is about 22 steps.
• The branching factor is about 3. (When the empty tile is in the middle,
four moves are possible; when it is in a corner, two; and when it is
along an edge, three.) This means that an exhaustive tree search to
depth 22 would look at about 3^22 ≈ 3.1×1010 states.
• A graph search would cut this down by a factor of about 170,000
because only 9!/2 =181, 440 distinct states are reachable. This is a
manageable number
• the corresponding number for the 15-puzzle is roughly 1013, so the
next order of business is to find a good heuristic function. If we want
to find the shortest solutions by using A∗, we need a heuristic
function that never overestimates the number of steps to the goal.
There is a long history of such heuristics for the 15-puzzle; here are
two commonly used candidates:
• h1 = the number of misplaced tiles. For Figure 3.28, all of the eight
tiles are out of position, so the start state would have h1 = 8. h1 is an
admissible heuristic because it is clear that any tile that is out of place
must be moved at least once.
• h2 = the sum of the distances of the tiles from their goal positions.
Because tiles cannot move along diagonals, the distance we will count
is the sum of the horizontal and vertical distances. This is sometimes
called the city block distance or Manhattan distance h2 is also
admissible because all any move can do is move one tile one step
DISTANCE closer to the goal. Tiles 1 to 8 in the start state give a
Manhattan distance of h2 = 3+1 + 2 + 2+ 2 + 3+ 3 + 2 = 18 .
• As expected, neither of these overestimates the true solution cost,
which is 26.
relaxed problems for the 8-puzzle.
Original 8-puzzle rule
• A tile can move from square A to square B if
• A is horizontally or vertically adjacent to B, and
• B is blank.
• (a) A tile can move from A to B if A is adjacent to B
• We removed condition (2) (no need for B to be blank).
• So a tile can move into any adjacent square, even if it’s not blank.
• What does this mean?
• The puzzle becomes like “tiles can swap places with neighbors.”
• This relaxed problem gives rise to the heuristic h1 = number of misplaced
tiles,
because in this relaxed version, each misplaced tile can move directly into
place (one step per tile).
• (b) A tile can move from A to B if B is blank
• We removed condition (1) (no need to be adjacent).
• So a tile can move into the blank from anywhere in the grid.
• What does this mean?
• A misplaced tile can “teleport” to the blank square in one step.
• To solve, each misplaced tile must move at least once → again this leads to h1
(misplaced tiles heuristic).
• (c) A tile can move from A to B
• We removed both conditions (no adjacency required, no blank
required).
• So a tile can jump to any square, at any time.
• What does this mean?
• Any tile can move directly to its goal square in one step.
• The total cost = sum of how far each tile is from its goal (row + column
distance).
• This gives us h2 = Manhattan distance heuristic.
• Original rule: must be adjacent + must move into blank.
• Relaxations:
• (a) → No blank needed → heuristic h1
• (b) → No adjacency needed → heuristic h1
• (c) → No restrictions → heuristic h2 (Manhattan distance)
• basically, heuristics come from relaxed versions of the problem:
• Misplaced tiles = relaxed so tiles can move freely into blank or swap.
• Manhattan distance = relaxed so tiles can move directly toward their
goals.
Generating admissible
heuristics from subproblems:
Pattern databases
• The idea of admissible heuristics
• A heuristic is admissible if it never overestimates the true cost to
reach the goal.
• Simple ones like misplaced tiles (h₁) or Manhattan distance (h₂) are
admissible, but not always strong enough.
• To do better, we can look at subproblems.
• Subproblems
• Instead of solving the full puzzle at once, pick a subset of tiles and
ask:
“How many moves are needed to get just these tiles into place
(ignoring the others)?”
• Example in 15-puzzle:
• Focus only on tiles {1,2,3,4,5,6,7,8}.
• Ignore tiles 9–15.
• This gives us a subproblem that is still meaningful but simpler.
• Pattern Database (PDB)
• A pattern database is a big lookup table.
• It stores the exact solution cost for every possible arrangement of the
chosen subset of tiles.
• Example:
• Suppose we choose tiles {1,2,3,4}.
• For every possible position of those tiles on the board, compute (by search)
how many moves it takes to put them in the correct places (ignoring the
other tiles).
• Store the result in the database.
• Using PDB as a heuristic
• During search, when we see a new state:
• Look at the positions of the chosen tiles.
• Fetch the precomputed cost from the PDB.
• This number is a lower bound (admissible), because solving the whole
puzzle must take at least as many moves as solving the subproblem.
• Goal:
123
456
78_
Suppose we build a pattern database for tiles {1,2,3,4}.
In some scrambled state:
312
4_5
678
• Look only at tiles 1,2,3,4.
• According to the PDB, their minimal cost to reach the correct position = 6 moves.
• So heuristic h(state) ≥ 6.
• Larger puzzles (like 15-puzzle)
• For the 15-puzzle, Manhattan distance is often too weak.
• Pattern databases can give much stronger heuristics:
• Example: split tiles into two disjoint sets (say {1–8} and {9–15}).
• Build two PDBs.
• During search, look up costs from both and add them → admissible and
powerful heuristic.