Heuristic Functions Interactive Demo

Explore Euclidean vs Manhattan Distance in A* Search

Understanding how heuristics guide intelligent pathfinding

Select Heuristic Function

Euclidean Distance
h(n) = √((x₂-x₁)² + (y₂-y₁)²)
Manhattan Distance
h(n) = |x₂-x₁| + |y₂-y₁|
A* Search & Heuristics

A* uses the evaluation function f(n) = g(n) + h(n) where:

  • g(n): Actual cost from start to node n
  • h(n): Heuristic estimate from node n to goal
  • f(n): Estimated total cost of path through n
Different heuristics lead to different search behaviors and efficiency!

Euclidean Distance Heuristic

Uses straight-line distance (as the crow flies). Provides the most direct estimate but may not be admissible in grid worlds with only 4-directional movement.

Search Controls
Legend
Start/Path
Goal
Obstacle
Current
Open List
Closed List
Ready to Start

Select a heuristic function above and click "Next Step" to begin A* search, or click "Show All Heuristics" to see values.

Current Status: Ready

A* Evaluation Function
f(n) = g(n) + h(n)
where:
g(n) = actual cost from start to n
h(n) = heuristic cost from n to goal
f(n) = total estimated cost
Current Node

No node selected

Heuristic Comparison
Property Euclidean Manhattan
Movement Diagonal allowed 4-directional
Admissible? Sometimes Yes
Performance Fewer explored More explored
Optimality Not guaranteed Guaranteed
Performance Metrics
0
Steps
0
Explored
-
Path Cost
-
Path Length

Understanding Heuristics in A* Search

Heuristic Properties
Admissible Heuristic

Never overestimates the actual cost. Guarantees optimal solution in A*.

Consistent Heuristic

Satisfies triangle inequality: h(n) ≤ c(n,n') + h(n'). Ensures efficient search.

Informative Heuristic

Closer to actual cost means fewer nodes explored. Balance accuracy vs computation.

Distance Formulas
Euclidean Distance
h(n) = √((x₂-x₁)² + (y₂-y₁)²)
Manhattan Distance
h(n) = |x₂-x₁| + |y₂-y₁|

Choose based on allowed movements in your problem domain.

Key Educational Insights
  • Euclidean: Good for problems allowing diagonal movement
  • Manhattan: Perfect for grid worlds with 4-directional movement
  • Admissibility: Critical for finding optimal solutions
  • Trade-off: More informative heuristics explore fewer nodes
  • Domain knowledge: Best heuristics reflect problem constraints
  • A* efficiency: Depends heavily on heuristic quality