~/ learn/ comp-456/ cards/ Heuristic & Adversarial Search
1 of 21

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/c8dd5aa7-e75b-4340-94ab-fa9d3e6eb4e1/flashcard utf-8 LF