Hill climbing is an iterative local search method that starts from one candidate solution and repeatedly moves to a better neighboring solution until no neighbor improves the objective function. In mathematical optimization and artificial intelligence, it is the simplest member of the greedy local search family and the baseline against which metaheuristics such as simulated annealing and tabu search are measured.
The method needs only two ingredients: a way to score a candidate and a way to generate neighbors. It requires no gradients, no convexity and no model of the search space, which makes it a natural choice for combinatorial and derivative-free problems. Its central weakness is equally simple: it stops at the first local optimum it reaches, which may be far from the global optimum.
How hill climbing moves through the search space
Hill climbing works by evaluating neighbors of the current state and accepting a move only when it improves the score. The algorithm treats the objective as a landscape: maximization means climbing toward peaks, while minimization is the same procedure applied to valleys. Each accepted move becomes the new current state, and the loop ends when the neighborhood contains no better candidate or a step budget runs out.
- Choose an initial state, often at random or from a quick heuristic.
- Generate the neighborhood with a defined move operator.
- Evaluate the objective for one, several or all neighbors.
- Move to an improving neighbor, or stop if none exists.
- Return the best state found.
The neighborhood definition shapes everything. For a traveling salesman tour, a neighbor might differ by a 2-opt edge swap; for a bit string, by one flipped bit; for a continuous vector, by a small random perturbation of one coordinate. A larger neighborhood finds better local optima but costs more evaluations per step, so the move operator is the main design decision in any hill climbing implementation.
Variants of hill climbing
Several variants change how the next move is selected or how the search restarts. The table below compares the forms most often used in practice and the situation each one suits.
| Variant | Move selection | Best suited to |
|---|---|---|
| Simple hill climbing | First improving neighbor found | Large neighborhoods, cheap scoring |
| Steepest-ascent hill climbing | Best neighbor after full scan | Small neighborhoods, precise steps |
| Stochastic hill climbing | Random improving neighbor | Reducing bias from neighbor order |
| Random-restart hill climbing | Repeated runs from new starts | Many local optima of varied quality |
| First-choice hill climbing | Random neighbors until one improves | Very large or implicit neighborhoods |
Random-restart hill climbing is the most important practical extension. If each run reaches the global optimum with probability p, the expected number of runs is about 1/p, so even a modest success rate per run becomes reliable after enough restarts. Many production solvers combine restarts with a stochastic move rule to keep each run inexpensive.
Local optima, plateaus and ridges
Hill climbing fails in predictable ways because it never accepts a worse move. Three landscape features cause most of these failures, and recognizing them explains why more elaborate metaheuristics exist.
| Feature | What happens | Typical remedy |
|---|---|---|
| Local optimum | All neighbors score worse | Random restarts or annealing |
| Plateau | Neighbors score equally | Allow sideways moves with a limit |
| Ridge | Improvement requires a diagonal step | Combine moves or rotate coordinates |
| Saddle region | Progress slows in flat directions | Larger perturbations |
A plateau is especially common in combinatorial problems with integer-valued objectives, where many neighbors tie. Allowing a bounded number of sideways moves, often a few hundred, lets the search cross a flat region without cycling forever. On a ridge, every single-coordinate move looks worse even though a combined move would improve the score, so the move operator itself must be redesigned.
How hill climbing compares with related methods
Hill climbing sits at the greedy end of a spectrum of local search methods. Related techniques differ mainly in whether and how they accept worse moves, and in how much memory they keep.
| Method | Accepts worse moves | Memory | Typical use |
|---|---|---|---|
| Hill climbing | Never | Current state only | Fast baseline, local refinement |
| Simulated annealing | With decreasing probability | Current state, temperature | Rugged landscapes |
| Tabu search | Yes, best non-tabu move | Recent move list | Scheduling, routing |
| Gradient descent | No | Current point, gradient | Differentiable continuous objectives |
| Genetic algorithm | Through selection pressure | Population | Broad global exploration |
Hill climbing is often described as the discrete counterpart of gradient descent. Both follow the locally best direction, but gradient descent computes it analytically, while hill climbing discovers it by sampling and comparing neighbors. In continuous spaces with available derivatives, gradient-based methods are usually far more efficient.
Where hill climbing is used in AI practice
Hill climbing remains useful wherever a good solution quickly matters more than a proven optimum. Typical applications include feature subset selection by adding or removing one feature at a time, structure learning for Bayesian networks by adding, deleting or reversing edges, and local refinement of schedules and routes produced by a constructive heuristic.
- Polishing the output of a genetic algorithm or other global method, an approach called memetic search.
- Tuning a small number of discrete hyperparameters when evaluations are cheap.
- Solving constraint satisfaction problems with min-conflicts moves, such as large n-queens instances.
When evaluations are expensive, as in training a deep network for each hyperparameter setting, hill climbing becomes wasteful because it spends many evaluations on small steps. Bayesian optimization or random search is then usually the better use of the budget.
Common mistakes and practical guidance
Most poor results come from design choices rather than the algorithm itself. The table lists frequent symptoms and how experienced practitioners address them.
| Symptom | Likely cause | Fix |
|---|---|---|
| Stops after a few steps | Neighborhood too small | Enrich the move operator |
| Same result every run | Deterministic start and order | Randomize start and neighbor order |
| Very slow progress | Full objective recomputed per move | Use incremental delta evaluation |
| Endless cycling | Unlimited sideways moves | Cap sideways moves |
Incremental evaluation is the most effective speedup: for a 2-opt move on a tour, the change in length depends on only four edges, so each neighbor costs constant time instead of linear time. Reporting the best score across restarts, together with the number of evaluations, gives a fair comparison with other methods.
The idea in brief
Imagine standing on a hillside in thick fog. You cannot see the summit. You can only feel the ground around your feet. So you take a step in whichever direction goes up. You repeat this until every direction goes down. That spot is a peak, but it may not be the highest one.
Hill climbing does the same with possible answers to a problem. It tries small changes and keeps the better ones. It is fast and simple. Its weakness is that it can get stuck on a small hill. Starting again from many different places is the usual cure.
A practical scenario
A regional delivery company plans daily routes for one van serving 60 stops. A dispatcher first builds a quick route with a nearest-neighbor rule, which produces a tour of about 210 kilometers. The planning software then applies hill climbing with 2-opt moves: it reverses a segment of the route whenever doing so shortens the total distance.
Each run evaluates thousands of swaps in under a second because only the changed edges are recomputed. The software repeats the process from 50 randomized starting routes and keeps the best result. The final tour measures about 182 kilometers, roughly 13 percent shorter than the initial route, which saves fuel and nearly half an hour of driving every day without requiring an exact solver.