# How do you calculate the heuristic value in this specific case?

The A* algorithm uses the "evaluation function" $$f(n) = g(n) + h(n)$$, where

• $$g(n)$$ = cost of the path from the start node to node $$n$$
• $$h(n)$$ = estimated cost of the cheapest path from $$n$$ to the goal node

But, in the following case (picture), how is the value of $$h(n)$$ calculated?

In the picture, $$h(n)$$ is the straight-line distance from $$n$$ to the goal node. But how do we calculate it?

The most obvious heuristic would indeed simply be the straight-line distance. In most cases, where you have, for example, x and y coordinates for all the nodes in your graph, that would be extremely easy to compute. The straight-line distance also fits the requirements of an admissible heuristic, in that it will never overestimate the distance. The travel-distance between two points can never be shorter than the straight-line distance (unless you start involving things like... teleportation).