๐ Heuristic Functions: Hamming & Manhattan
164 words
1 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# ๐ Heuristic Functions: Hamming & Manhattan ## 1. ๐ฏ Learning Objectives - Compute Hamming and Manhattan distances for the 8-puzzle - Explain why Manhattan dominates Hamming - Design admissible heuristics for other problems ## 2.

๐ Heuristic Functions: Hamming & Manhattan
1. ๐ฏ Learning Objectives
- Compute Hamming and Manhattan distances for the 8-puzzle
- Explain why Manhattan dominates Hamming
- Design admissible heuristics for other problems
2. ๐ Core Content
3.1 Hamming Distance (Misplaced Tiles)
Count of tiles not in their goal positions (excluding the blank). State: [2,8,3][1,6,4][7,0,5] Goal: [1,2,3][8,0,4][7,6,5] Tiles not in place: 1,2,6,8? Let's count: 2โ 1, 8โ 2, 1โ 8, 6โ 0? No 6โ 6? Actually check each: (0,0)=2 vs 1โ,(0,1)=8 vs 2โ,(0,2)=3 vs 3โ,(1,0)=1 vs 8โ,(1,1)=6 vs 0โ,(1,2)=4 vs 4โ,(2,0)=7 vs 7โ,(2,1)=0 vs 6โ,(2,2)=5 vs 5โ. Hamming=5.
3.2 Manhattan Distance
Sum of |xโ-xโ|+|yโ-yโ| for each tile. For tile 1: current(1,0) goal(0,0) = 1+0 = 1. Tile 2: (0,0) to (0,1) = 1. Tile 8: (0,1) to (1,0) = 2. Sum = 5.
3.3 Dominance
Manhattan โฅ Hamming for all states (every misplaced tile has Manhattan โฅ 1). A* with Manhattan never expands more nodes than A* with Hamming.
Join Discord
PreviousHeuristic DesignNextHill Climbing