AlgorithmsFoundational

Heuristics: Manhattan vs Euclidean Distance

A heuristic is a guess about remaining cost; the right guess depends on how movement is allowed.

A*HeuristicsGeometryPathfinding

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

hmanhattan=x1x2+y1y2h_{manhattan}=|x_1-x_2|+|y_1-y_2|

heuclidean=(x1x2)2+(y1y2)2h_{euclidean}=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}

Grid streetsManhattan distance matches movement where diagonal steps are not legal.
Open planeEuclidean distance matches straight-line movement.
GuaranteeThe heuristic should not overestimate if shortest-path optimality matters.

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 modelBetter heuristic
Four-direction gridManhattan
Eight-direction gridDiagonal or octile distance
Continuous spaceEuclidean
Unknown cost terrainDomain-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?
  1. Manhattan
  2. Euclidean
  3. Random
  4. No heuristic can work

Manhattan distance counts horizontal and vertical steps, matching four-direction movement.

Sources and Further Reading

Related Explainers