๐Ÿ“ Heuristic Functions: Hamming & Manhattan

164 words
1 min read
Python Week 1: the first filter for runtime behavior
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
Document outline

Keep your place and jump directly to a heading.

Table of contents

No note selected

Open a chapter to see its outline, backlinks, and sources here.