~/ learn/ comp-456/ cards/ Why heuristics? Hill-climbing and the local-maximum trap
1 of 4

The hill-climbing step: move to the best neighbour, else stop

The hill-climbing step: move to the best neighbour, else stop

Answer

best, best_val = x, f(x) for nxt in (x - 1, x + 1): if f(nxt) > best_val: best, best_val = nxt, f(nxt) if best == x: return x, best_val # local/global maximum x = best

No frontier, no visited set — only the single best child survives. When no neighbour beats the current value, the search is stuck (it may be a local maximum).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/faafe441-119e-4090-b2f1-5bbf8fd128ff/flashcard utf-8 LF