About this visualization
Hill climbing is a local search: it looks only at the neighbours of the current node, moves to the best one and never looks back. It uses almost no memory and is fast, but it can stop at a local optimum or plateau that is not the goal. This simulator lets you watch it succeed and fail.
How it works
- Start at the start node and compare the heuristic of all neighbours.
- Move to the neighbour with the lowest h — only if it is better than the current node.
- If no neighbour is better, stop: this is a local optimum (or a plateau). It cannot backtrack.
Formulas used
- Move to if
Worked example
In the local-minimum trap graph the start has h = 5 and neighbours A (h = 3) and B (h = 4). Hill climbing moves to A, whose only other neighbour D has h = 4 — no improvement, so it stops at A even though the goal is reachable via B and C. A* and beam search with k = 2 find the goal.
Enter these numbers in the simulator above to see every step.
Complexity and properties
| Worst case | |
|---|---|
| Space |
Neither complete nor optimal: local minima and plateaus can stop it. Sideways moves help on plateaus.
When to use it
- Understanding local search and optimisation in AI.
- Seeing local maxima, plateaus and why random restarts are used.
- Comparing with beam search (k = 1 is hill climbing).
Frequently asked questions
What is the local maximum problem in hill climbing?
The climber reaches a point better than all its neighbours that is not the best overall (or the goal) and cannot escape because it never moves to a worse node.
Is hill climbing complete or optimal?
Neither: it can get stuck, and when it finishes the answer is not guaranteed to be the best.
How can hill climbing escape plateaus?
By allowing a limited number of sideways moves, random restarts, or using simulated annealing.