Why heuristics? Hill-climbing and the local-maximum trap
◈ 4 cardsThe two situations that demand heuristics, hill-climbing as the simplest heuristic search, and why discarding history makes it get stuck.
What a heuristic is
A heuristic is an informed rule of thumb — a cheap estimate of how close a state is to a goal — used to steer search toward the promising parts of a space. The word is from the Greek eurisco, "I discover." Heuristics are fallible: they can lead to a worse-than-optimal answer or miss a solution entirely, and that limitation cannot be engineered away.
There are exactly two situations where you reach for a heuristic:
- No exact algorithm exists because the problem is inherently ambiguous — medical diagnosis, interpreting a noisy image. There is no formula that is guaranteed right.
- An exact algorithm exists but is too expensive — the state space is combinatorially huge (chess, the 15-puzzle). Exhaustive search is correct in principle but would never finish.
Hill-climbing: the simplest heuristic search
Hill-climbing keeps no history at all. From the current state it generates the children, evaluates each with the heuristic, moves to the single best child, and discards everything else — the siblings and the parent. It then repeats. It is fast and uses almost no memory.
That discard-everything policy is its fatal flaw: with no record of where it has been, hill-climbing cannot back up. If it reaches a state that looks better than all of its neighbours but is not the global best — a local maximum — it has no move that improves the score and simply stops, stranded on a foothill below the summit.
Worked example: a one-dimensional landscape
Give each integer position a value . Picture two hills: a small one peaking at () and the true summit at (), with a valley between them.
- Start at . Each step compares and and walks to the higher neighbour. Climbing , then , so no neighbour improves — hill-climbing halts at the local maximum .
- Start at . The uphill path leads straight to , the global maximum.
Same algorithm, same landscape — the starting point decides whether you find the real peak. That is the local-maximum trap, and it is exactly why richer searches (best-first, next lesson) keep all generated states so they can recover from a bad heuristic choice.