Memra

Why heuristics? Hill-climbing and the local-maximum trap

◈ 4 cards

The 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:

  1. No exact algorithm exists because the problem is inherently ambiguous — medical diagnosis, interpreting a noisy image. There is no formula that is guaranteed right.
  2. 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.

012345678910f(x)0354213710128stops heresummitclimb from x=0from x=8The index is x; the cell holds f(x).
Same algorithm, same landscape, two start points. From x = 0 the climb 0 → 1 → 2 stops dead because f(3) = 4 is lower than f(2) = 5 and hill-climbing keeps no history to back up with; from x = 8 the uphill path runs straight to the summit.
NORMAL ~/memra/learn/comp-456/why-heuristics-hill-climbing utf-8 LF