Admissible Heuristics Exercise

8-Puzzle Analysis with Step-by-Step Solutions

Understanding h₁ and h₂ heuristics systematically

Problem Statement

We analyze the 8-puzzle (3×3 sliding tile puzzle). The goal is to slide numbered tiles to match the target configuration:

Goal State:
1 2 3
4 5 6
7 8 _
Heuristics to Analyze
  • h₁(n): Number of misplaced tiles (not counting the blank)
  • h₂(n): Sum of Manhattan distances (rows + columns away from goal positions)
Learning Outcomes

By completing this exercise, you will be able to:

  • Prove heuristic admissibility using logical reasoning and mathematical principles
  • Calculate heuristic values (h₁ and h₂) for 8-puzzle states step-by-step
  • Evaluate heuristic quality and understand why more informed heuristics improve A* efficiency
  • 1. What does it mean for a heuristic to be admissible?
  • 2. Why does admissibility guarantee that A* search will find an optimal solution?
Solution - Understanding Admissibility
1 Admissible heuristic: Never overestimates the true cost to the goal
Mathematical definition: $h(n) \leq h^*(n)$ for all nodes $n$
where $h^*(n)$ is the true optimal cost from $n$ to goal
2 A* optimality guarantee: If $h(n)$ is admissible, then A* will find the optimal solution
Why: A* expands nodes in order of $f(n) = g(n) + h(n)$. Since $h(n) \leq h^*(n)$, the first time A* reaches the goal, it must be via the optimal path.
Explanation - How to Think About Admissibility

Think of admissibility as "never lying about how easy the problem is":

🎯 Real-world analogy: Imagine you're estimating driving time to the airport:
  • Admissible estimate: "It takes at least 30 minutes" (could be 30, 35, or 45 minutes)
  • Non-admissible estimate: "It takes at most 20 minutes" (but actually takes 30 minutes)
🧩 For puzzles, this means:
  • If your heuristic says "need at least 5 moves," the real answer could be 5, 6, 7, or more moves
  • If your heuristic says "need at least 5 moves," but the real answer is only 3 moves, then your heuristic is non-admissible
📚 How to solve similar problems:
  1. Ask: "What's the minimum number of steps needed?"
  2. Find a lower bound: Something that must be done at least once
  3. Check: Can this estimate ever be higher than the real cost? If no → admissible ✓
  • 3. For any state, can h₁(n) ever overestimate the true number of moves to the goal?
  • 4. Give a short reasoning why h₁ is admissible.
Solution - h₁ Admissibility
3 Can h₁ overestimate? No, it cannot.
Logic: Each misplaced tile must move at least once to reach its correct position. Since each move can fix at most one tile, the minimum number of moves needed is at least the number of misplaced tiles.
4 h₁ admissibility proof:
• Each misplaced tile requires ≥ 1 move to fix
• Each move can fix ≤ 1 tile
• Therefore: true cost ≥ number of misplaced tiles = h₁(n)
• So h₁(n) ≤ h*(n) ✓
Explanation - Understanding the Misplaced Tiles Heuristic

Think of h₁ as counting "How many tiles are in the wrong room?"

🏠 Simple analogy: Imagine organizing books on shelves:
  • You have 8 books that need to go to specific shelves
  • Currently, 6 books are on wrong shelves
  • You need at least 6 moves to fix this (each move can fix at most 1 book)
🎯 Why it's admissible (step-by-step logic):
  1. Each wrong tile needs fixing: If a tile is in the wrong position, it must move
  2. One move fixes at most one tile: Each slide can only move one tile at a time
  3. Therefore: If 6 tiles are wrong, you need at least 6 moves
  4. The real solution might need more moves (but never fewer than 6)
📚 How to apply this to any puzzle:
  1. Compare current state to goal state
  2. Count elements in wrong positions
  3. That count = minimum moves needed (each move fixes ≤ 1 element)
This works for any puzzle where one move affects one element!
  • 5. For any tile, why is its Manhattan distance a lower bound on the number of moves needed to place it correctly?
  • 6. Why does summing over all tiles still give an admissible heuristic h₂?
Solution - h₂ Admissibility
5 Manhattan distance as lower bound:
• Manhattan distance = |row₁ - row₂| + |col₁ - col₂|
• Each move changes position by exactly 1 step (up/down/left/right)
• To move distance $d$, you need at least $d$ moves
• Therefore: moves needed ≥ Manhattan distance
6 Sum remains admissible because:
• Each move affects only one tile's position
• Total moves needed ≥ sum of individual tile requirements
• Therefore: h₂(n) = Σ(Manhattan distances) ≤ h*(n) ✓
Explanation - Understanding Manhattan Distance

Think of Manhattan distance as "city blocks you need to walk":

🏙️ City block analogy: Imagine you're in Manhattan (New York):
  • You're at corner of 2nd Street & 3rd Avenue
  • You need to get to 5th Street & 7th Avenue
  • Manhattan distance: |5-2| + |7-3| = 3 + 4 = 7 blocks
  • You cannot walk diagonally through buildings!
🧩 For our puzzle, each tile needs to "walk" to its home:
Example: Tile 5 is at position (3,3)
But it belongs at position (2,2)
Distance: |3-2| + |3-2| = 1 + 1 = 2 steps
Current → Goal
(3,3) → (2,2)
2 steps minimum
🎯 Why h₂ is more informed than h₁:
  • h₁ says: "This tile is wrong" (value = 1)
  • h₂ says: "This tile is 3 steps away from home" (value = 3)
  • h₂ gives more information! It considers HOW FAR wrong each tile is
📚 How to calculate Manhattan distance for any grid:
  1. Find current position: (current_row, current_col)
  2. Find target position: (target_row, target_col)
  3. Calculate: |current_row - target_row| + |current_col - target_col|
  4. Sum for all elements: Total = sum of all individual distances
This works for any grid-based puzzle!
Current State:
2 8 3
1 6 4
7 _ 5
  • 7. Compute h₁ and h₂ for this state.
  • 8. Which heuristic is more informed (closer to the true cost-to-goal)?
Step-by-Step Calculation
Calculate h₁ (Misplaced Tiles):
1 Count misplaced tiles:
• Tile 1: at (2,1), should be at (1,1) → Misplaced ✗
• Tile 2: at (1,1), should be at (1,2) → Misplaced ✗
• Tile 3: at (1,3), should be at (1,3) → Correct ✓
• Tile 4: at (2,3), should be at (2,1) → Misplaced ✗
• Tile 5: at (3,3), should be at (2,2) → Misplaced ✗
• Tile 6: at (2,2), should be at (2,3) → Misplaced ✗
• Tile 7: at (3,1), should be at (3,1) → Correct ✓
• Tile 8: at (1,2), should be at (3,2) → Misplaced ✗
2 h₁ = 6 misplaced tiles (2, 8, 1, 6, 4, 5)
Calculate h₂ (Manhattan Distance):
3 Calculate each tile's Manhattan distance:
• Tile 1: from (2,1) to (1,1) = |2-1| + |1-1| = 1
• Tile 2: from (1,1) to (1,2) = |1-1| + |1-2| = 1
• Tile 3: from (1,3) to (1,3) = |1-1| + |3-3| = 0
• Tile 4: from (2,3) to (2,1) = |2-2| + |3-1| = 2
• Tile 5: from (3,3) to (2,2) = |3-2| + |3-2| = 2
• Tile 6: from (2,2) to (2,3) = |2-2| + |2-3| = 1
• Tile 7: from (3,1) to (3,1) = |3-3| + |1-1| = 0
• Tile 8: from (1,2) to (3,2) = |1-3| + |2-2| = 2
4 h₂ = 1 + 1 + 0 + 2 + 2 + 1 + 0 + 2 = 9

Heuristic Comparison Results

h₁ (Misplaced Tiles)
6

Counts tiles in wrong positions

h₂ (Manhattan Distance)
9

Sum of distances to correct positions

h₂ is more informed: 9 > 6, so h₂ provides better guidance to A*
Explanation - Step-by-Step Problem-Solving Strategy

Here's how to approach ANY heuristic calculation systematically:

🗂️ Step-by-Step Method:
  1. Set up a table: List each tile, current position, goal position
  2. Calculate individually: Work on one tile at a time
  3. Double-check positions: Use (row, column) coordinates consistently
  4. Sum carefully: Add up all individual contributions
💡 Pro tips for avoiding mistakes:
  • Use a systematic order: Go through tiles 1, 2, 3, 4, 5, 6, 7, 8
  • Skip correctly placed tiles: If tile is already correct, distance = 0
  • Always use absolute values: |difference| ensures positive distances
  • Check your goal state: Make sure you know where each tile belongs!
🧮 Quick mental check:
  • h₂ should always be ≥ h₁ for the same state
  • If h₂ < h₁: You made a calculation error!
  • Both should be > 0 unless you're at the goal state
  • 9. Between h₁ and h₂, which heuristic would you expect to make A* more efficient? Why?
  • 10. Can a heuristic be admissible but still uninformative? Give an example.
Solution - Heuristic Efficiency
9 h₂ makes A* more efficient because:
• h₂ dominates h₁: h₂(n) ≥ h₁(n) for all states
• Higher heuristic values → better guidance → fewer nodes expanded
• A* with h₂ will expand fewer nodes than A* with h₁
• Both are admissible, so both guarantee optimal solutions
10 Uninformative but admissible heuristic example:
• h(n) = 0 for all states
• This is admissible (never overestimates)
• But provides no guidance at all
• A* with h(n) = 0 becomes Uniform-Cost Search
Key Insights
  • Admissibility: Ensures optimal solution
  • Informativeness: Higher values → better efficiency
  • Dominance: If h₂(n) ≥ h₁(n) always, then h₂ dominates h₁
  • Trade-off: More informed heuristics may be more expensive to compute
Explanation - Practical Understanding of Heuristic Quality

Think of heuristics as "GPS directions with different levels of detail":

🗺️ Analogy - Navigation systems:
h(n) = 0:
"Just start driving"
No guidance at all
h₁:
"You're in wrong city"
Basic direction
h₂:
"You're 15 miles away"
Precise guidance
🎯 Real-world impact on A* search:
  • Better heuristic = fewer wrong turns: A* explores fewer dead-end paths
  • Time savings are dramatic: Could mean 1000 vs 10,000 nodes explored!
  • Still get same answer: Both find the optimal solution
📚 How to evaluate heuristics in practice:
  1. Check admissibility first: Does it ever overestimate? (Run tests!)
  2. Compare informativeness: Which gives higher values on average?
  3. Consider computation cost: Is the better guidance worth the extra time?
  4. Test on real problems: Measure actual search performance
🚨 Common student mistake: "Higher is always better"
Remember: Higher is only better if it stays admissible! A non-admissible heuristic might give wrong answers.
What We Proved
  • Both h₁ and h₂ are admissible
  • h₂ dominates h₁ (h₂ ≥ h₁ always)
  • A* with either finds optimal solutions
  • A* with h₂ is more efficient
Practical Guidelines
  • Always verify admissibility before using
  • More informed = fewer expansions
  • Consider computation cost vs. guidance benefit
  • Test on representative problems
Common Mistakes to Avoid
❌ Calculation Errors:
  • Mixing up row/column coordinates
  • Forgetting absolute values in Manhattan distance
  • Counting blank tile as misplaced
  • Using wrong goal state positions
❌ Conceptual Errors:
  • Using non-admissible heuristics
  • Assuming higher is always better
  • Ignoring computation cost
  • Not testing on diverse problems
✅ Pro tip: Always double-check your calculations by working through a simple example first!

Continue Learning