Heuristics: Manhattan vs Euclidean Distance
A heuristic is a guess about remaining cost; the right guess depends on how movement is allowed.
Site connection
The path finder project supports taxicab and Euclidean heuristics, making this a natural comparison page.
Visual model
Heuristic pressure changes the frontier
Toggle the demo and watch how the path frontier changes when the estimated distance changes.
Interactive
A* expands likely paths first instead of flooding the whole grid
What the Heuristic Is Doing
The heuristic does not move the agent. It ranks candidates by giving the algorithm a directional estimate.
A weak heuristic expands too much. An overconfident heuristic can become greedy and wrong.
Choosing the Distance
Manhattan distance is right for four-neighbor grids. Euclidean distance is natural when diagonal or continuous movement is allowed.
| Movement model | Better heuristic |
|---|---|
| Four-direction grid | Manhattan |
| Eight-direction grid | Diagonal or octile distance |
| Continuous space | Euclidean |
| Unknown cost terrain | Domain-specific estimate |
Common Pitfalls
- Using Euclidean distance on a four-direction grid without checking admissibility.
- Assuming a more complex heuristic is automatically better.
- Forgetting that terrain costs can make geometric distance misleading.
Quick check
Quiz
Which heuristic fits four-direction grid movement best?
- Manhattan
- Euclidean
- Random
- No heuristic can work
Manhattan distance counts horizontal and vertical steps, matching four-direction movement.