Artificial intelligence • Original RRTutors lesson
Informed Search and Heuristic Functions
Use a heuristic estimate to prioritize promising states while preserving search guarantees.
Concept and explanation
A heuristic h(n) estimates the remaining cost from state n to a goal. Greedy best-first search prioritizes h alone and may be fast but not optimal. A* prioritizes g(n) + h(n), combining known cost with estimated remaining cost; admissibility and consistency conditions affect its guarantees.
How to apply it
Check that heuristic units match path costs, test it against exact distances on small problems, and distinguish admissible from merely plausible estimates.
Worked example
Manhattan distance is admissible on a four-direction grid with unit movement costs when obstacles only increase path length.
Illustrative Python example
def manhattan(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
print(manhattan((1, 2), (4, 6)))
Expected result
The Manhattan estimate is 7 grid steps.
Limitations and cautions
An overestimating heuristic can cause A* to return a non-optimal route.
Practice exercise
Design a heuristic for a small puzzle and test admissibility against all states in a tiny instance.
Key takeaway: A heuristic is useful only when its assumptions and guarantees are understood.