Hill climbing moves to a better neighbor until none is better, stopping at a local optimum that need not be global. On the 100-city kroA100 (2-opt moves, 30 seeded starts) no variant reached the optimum. Median excesses were 6.8% for steepest ascent (104 moves), 5.6% for first improvement and 10.9% for first-choice, at a seventeenth of the cost in evaluations. The pivot rule can change where a climb ends: on a 25 by 25 grid, first improvement shrinks the global peak's basin from 238 to 185 cells. A climber stops at strict local maxima, plateaus and ridges; sideways moves cross a shoulder $m$ moves long in $m^2$ steps on average. The $(1+1)$ EA has no strict local optima, but waits at least $n^k$ steps for an improvement $k$ bits away.
Take a tour of the 100 cities in kroA100, a standard instance from the TSPLIB library (Reinelt, 1991), and put the cities in random order. The resulting tour is typically about eight times as long as the shortest one, whose length, 21,282, is known. Now look at every pair of edges in the tour. Ask how much shorter the tour would be if those two edges were removed and the tour reconnected by reversing the path between them. Make the change that shortens the tour the most, and repeat until no pair of edges gives any improvement. Starting from 30 random tours, this procedure needed a median of 104 such moves and ended at tours a median of 6.8% longer than the optimum. It never reached the optimum, and when it stopped, it could not tell how far away the optimum was. Why does a procedure that improves the tour at every step stop short, and does the way it picks its steps matter? It stops short because it compares a tour only with the tours one move away, and a tour can be shorter than all of those without being the shortest. The way it picks its steps does matter: it changes what a climb costs and can change where the climb ends.
That procedure is hill climbing, the simplest form of local search. It holds one candidate solution and looks only at solutions that differ from it by one small change. It moves to a better one until there is none. Later articles in the unit build on the variants and failure modes defined here.
First we set out the three ingredients of a local search and look closely at the move used on kroA100. Then we specify the four standard variants completely and trace two of them on a grid small enough to draw. Next we measure what each variant costs on kroA100. Then we look at the features of a problem that stop a hill climber. Finally we read the simplest evolutionary algorithm as a hill climber. The article assumes the vocabulary of fitness landscapes: neighborhoods, local optima, and basins of attraction.
The three ingredients
A local search problem has three parts (Russell and Norvig, 2020, §4.1):
- a set $X$ of states, each a complete candidate solution: a tour that visits every city, a bitstring, a placement of eight queens on a board;
- a neighborhood $N(x) \subseteq X$ for each state, the states reachable by one move;
- an objective $f : X \to \mathbb{R}$ to be maximized, or a cost to be minimized.
These are exactly the three parts of a fitness landscape. The neighborhood is not given by the problem. It is a design choice.
For the traveling salesman problem (TSP), the move in the example above is the 2-opt move. Croes (1958) introduced it, and Lin (1965) generalized it to $k$ edges. It removes two edges and reconnects the two paths that remain in the only other way that gives a tour, which reverses one of them. A tour of $n$ cities has $n(n-3)/2$ distinct 2-opt moves, 4,850 for $n = 100$. Other problems have their own natural moves:
- for bitstrings of length $n$, the usual neighborhood is the $n$ strings one bit flip away;
- for the 8-queens problem with one queen per column, a move shifts one queen within its column, giving $8 \times 7 = 56$ neighbors.
The 2-opt move in detail
The TSP experiments below count everything in 2-opt moves, so it is worth seeing one move completely. Take eight cities $A$ to $H$ visited in that order. Choose two edges that do not share a city, say $B\text{-}C$ and $F\text{-}G$. Deleting them leaves two paths, $C\,D\,E\,F$ and $G\,H\,A\,B$. There are two ways to join two paths into a cycle:
- the original one, $B\text{-}C$ and $F\text{-}G$;
- the crossed one, $B\text{-}F$ and $C\text{-}G$.
The crossed one gives the tour $A\,B\,F\,E\,D\,C\,G\,H$. That is the original with the segment $C\,D\,E\,F$ reversed. This is why a 2-opt move is usually implemented as a reversal of a stretch of the tour.
Two facts follow from this picture.
- A move is cheap to evaluate. Only four edges change, so the change in tour length is $$\Delta = d(B, F) + d(C, G) - d(B, C) - d(F, G),$$ four distance lookups, whatever the number of cities. The reversed segment is traversed in the opposite direction. With symmetric distances its length does not change. This four-term difference is what the article calls one evaluation.
- The neighborhood has $n(n-3)/2$ members. The count is every pair of edges, less the pairs that cannot be reconnected. A tour of $n$ cities has $n$ edges, so there are $\binom{n}{2} = n(n-1)/2$ pairs of edges. The $n$ pairs of adjacent edges share a city and cannot be reconnected any other way, so they give no move. That leaves $n(n-1)/2 - n = n(n-3)/2$ moves, and different pairs give different tours. The reason is that the two new edges are not edges of the original tour. In the example, $B\text{-}F$ or $C\text{-}G$ would be one only if $F$ came just before $B$ or $G$ came just after $C$, and each of those makes the two removed edges adjacent. So the new tour contains every original edge except the two removed, and the removed pair can be read off it.
Example (the eight-city tour). The eight-city tour has twenty 2-opt moves. There are $\binom{8}{2} = 28$ pairs of edges, and the 8 adjacent pairs give no move, so $28 - 8 = 20 = 8 \times 5 / 2$. For kroA100 the same count is $100 \times 97 / 2 = 4{,}850$.
When $\Delta < 0$ the move shortens the tour. A 2-opt local optimum is a tour for which all $n(n-3)/2$ values of $\Delta$ are nonnegative. What does such a tour look like? Here is the claim in one sentence: with Euclidean distances, a tour whose path crosses itself always has an improving 2-opt move, so a 2-opt local optimum never crosses itself.
The argument uses the triangle inequality. Suppose the tour runs $a, b, \ldots, c, d, \ldots$ and back to $a$ (orient the tour so that it traverses one of the crossing edges first, from $a$ to $b$, and the other later, from $c$ to $d$), and that its edges $a\text{-}b$ and $c\text{-}d$ cross at a point $X$ inside both. The 2-opt move on these two edges replaces them with $a\text{-}c$ and $b\text{-}d$. (The other pairing, $a\text{-}d$ and $b\text{-}c$, would close the path from $b$ to $c$ into a loop of its own and is not a tour.) The triangle inequality gives
$$d(a, c) \le d(a, X) + d(X, c), \qquad d(b, d) \le d(b, X) + d(X, d).$$
Add the two. Because $X$ lies on the segment from $a$ to $b$, $d(a, X) + d(X, b) = d(a, b)$, and because it lies on the segment from $c$ to $d$, $d(c, X) + d(X, d) = d(c, d)$. So the right-hand sides add up to $d(a, b) + d(c, d)$, and
$$d(a, c) + d(b, d) \le d(a, b) + d(c, d).$$
The inequality is strict unless all four cities lie on one line. Equality in $d(a, c) \le d(a, X) + d(X, c)$ requires $X$ to lie on the segment from $a$ to $c$. Then $b$ and $c$ both lie on the line through $a$ and $X$, and so does $d$, which is on the line through $c$ and $X$. Otherwise $\Delta < 0$ for this move, and the tour is not a local optimum.
One caveat applies to kroA100. TSPLIB rounds each distance to the nearest integer, so a gain smaller than the rounding can disappear, and the proof covers exact Euclidean distances only. The local optimum pictured later in the article has no crossing edges, as the proof leads us to expect, even though it is 2.5% longer than the best tour.
Because the state is a complete solution, a local search needs almost no memory: one state, and the best value seen. It also produces an answer at any time. That is why local search is used on problems far too large to search systematically (Russell and Norvig, 2020, §4.1). The names follow the direction of improvement. When $f$ is a fitness to maximize, the search climbs; when it is a cost such as tour length, the same algorithm is called descent. This article writes $f$ as a quantity to maximize, and the TSP examples minimize tour length.
With the ingredients fixed, one choice remains: which improving neighbor the search takes. The next section specifies the four standard ways of making it.
Four variants, completely specified
Every hill climber repeats one step. From the current state $x$, it chooses a neighbor $y$ by some rule, and moves to it if $f(y) > f(x)$. The variants differ in how $y$ is chosen, and therefore in how many neighbors must be evaluated per step.
Eiben and Smith (2015, §10.2) call this choice the pivot rule. One option is to stop at the first improving neighbor (greedy ascent, also called first improvement). The other is to examine them all and take the best (steepest ascent). Russell and Norvig (2020, §4.1.1) add two randomized variants. A complete specification must also say how ties are broken and when the search stops. An algorithm that leaves these open is not deterministic given a random seed, and its results cannot be reproduced.
First-improvement hill climbing (sometimes called simple hill climbing).
- Fix an order on the moves, for example the 2-opt moves $(i, j)$ sorted by $i$, then by $j$.
- Scan the neighbors of $x$ in that order. Move to the first neighbor $y$ with $f(y) > f(x)$.
- After a move, start the next scan from the beginning of the order. (A common alternative continues from where the last scan stopped. The two can end at different local optima.)
- Stop when a complete scan finds no improving neighbor.
Steepest-ascent hill climbing.
- Evaluate every neighbor of $x$.
- Let $f^* = \max_{y \in N(x)} f(y)$. If $f^* \le f(x)$, stop.
- Otherwise move to a neighbor with value $f^*$. If several share it, choose by a fixed rule, such as the first in the move order, or uniformly at random.
Stochastic hill climbing (Russell and Norvig, 2020, §4.1.1).
- Evaluate every neighbor of $x$ and collect the improving ones, $U = \{ y \in N(x) : f(y) > f(x) \}$.
- If $U$ is empty, stop.
- Otherwise move to a member of $U$ chosen at random: uniformly, or with probability that increases with the size of the improvement.
First-choice hill climbing (Russell and Norvig, 2020, §4.1.1).
- Generate neighbors of $x$ at random, one at a time, and move to the first one that is better than $x$.
- The stopping rule has to be chosen. If neighbors are drawn without replacement, in a fresh random order at each step, the search knows it is at a local optimum when the order is exhausted. If they are drawn with replacement, it must stop after some fixed number of consecutive failures. It may then stop at a state that still has an improving neighbor.
Russell and Norvig recommend first-choice hill climbing when a state has very many neighbors, since it usually evaluates only a few of them per step. Stochastic hill climbing, in their account, usually climbs more slowly than steepest ascent but sometimes finds better solutions.
Example (the final scan cannot be skipped). First-choice hill climbing often finds an improvement after a handful of evaluations, but no variant can stop at a true local optimum after only a handful. All four stop at a local optimum, a state no neighbor improves on (first-choice only when it draws without replacement). All four certify it the same way: by evaluating the whole neighborhood once and finding nothing better.
The reason is that the objective is known only through evaluations. Suppose a hill climber stops at $x$ without having evaluated some neighbor $y$. Nothing it has computed rules out $f(y) > f(x)$, so it cannot know that $x$ is a local optimum. The four variants keep no record of earlier evaluations, so each must evaluate all of $N(x)$ at the state where it stops. A climb that ends at a true local optimum therefore costs at least one full scan: 4,850 evaluations on kroA100, however cheap the earlier steps were.
A worked example: two pivot rules on a small grid
The pivot rule changes more than the cost of a climb. It can also change where the climb ends. The difference is easiest to see on a problem small enough to draw.
The states are the cells $(x, y)$ of a 25 by 25 grid, $0 \le x, y \le 24$. Each cell has up to four neighbors: the cells directly above, to the right, below, and to the left, scanned in that order. The objective is an integer height made of four hills, labeled $A$ to $D$, with peaks of 655, 893, 1046, and 669. A gentle tilt keeps the low ground between the hills from being flat. (The heights are $10 \times$ a sum of four Gaussian bumps and the tilt $0.3x + 0.2y$, rounded to integers; the script named at the end of this section lists the parameters.) Every cell other than the four peaks has a strictly higher neighbor. So the only places a hill climber can stop are the peaks, and $C$, at $(11, 6)$, is the global maximum.
Start both rules at $(17, 4)$, on the lower slope between $C$ and $D$. Steepest ascent reads all four neighbors and takes the highest:
| Step | Cell | $f$ | Up | Right | Down | Left | Move |
|---|---|---|---|---|---|---|---|
| 0 | (17, 4) | 471 | 532 | 463 | 389 | 524 | up |
| 1 | (17, 5) | 532 | 556 | 536 | 471 | 582 | left |
| 2 | (16, 5) | 582 | 605 | 532 | 524 | 679 | left |
| 3 | (15, 5) | 679 | 702 | 582 | 617 | 797 | left |
| 4 | (14, 5) | 797 | 824 | 679 | 727 | 909 | left |
| 5 | (13, 5) | 909 | 939 | 797 | 829 | 987 | left |
| 6 | (12, 5) | 987 | 1019 | 909 | 900 | 1013 | up |
| 7 | (12, 6) | 1019 | 992 | 939 | 987 | 1046 | left |
| 8 | (11, 6) | 1046 | 1018 | 1019 | 1013 | 1012 | stop |
It reaches the global maximum $C$ in 8 moves. It has evaluated $9 \times 4 = 36$ neighbors, including the final scan at $(11, 6)$ that finds nothing higher.
Example (first improvement at $(17, 5)$). At $(17, 5)$ first improvement moves up, to 556, where steepest ascent moved left. First improvement scans the same neighbors in the same order (up, right, down, left) but takes the first one that is higher than the current cell. From $(17, 4)$ it also moves up first, since 532 is higher than 471. At $(17, 5)$ the steepest-ascent table gives the cell above as 556. That is higher than the current 532, and it is scanned first, so first improvement never looks at the cell to the left, worth 582. Here is the whole run:
| Step | Cell | $f$ | Neighbors read | First higher neighbor | Move |
|---|---|---|---|---|---|
| 0 | (17, 4) | 471 | up | up 532 | up |
| 1 | (17, 5) | 532 | up | up 556 | up |
| 2 | (17, 6) | 556 | up, right | right 565 | right |
| 3 | (18, 6) | 565 | up, right | right 614 | right |
| 4 | (19, 6) | 614 | up, right | right 662 | right |
| 5 | (20, 6) | 662 | up, right | right 669 | right |
| 6 | (21, 6) | 669 | all four | none | stop |
The two runs part company at step 1, and that one choice decides the outcome. It puts first improvement on the slope of $D$, and it climbs to $D$'s peak of 669 in 6 moves and 14 evaluations. Steepest ascent spent 36 evaluations and reached a peak more than half as high again. Neither outcome is a property of the start alone. It is a property of the start together with the pivot rule.
Running both rules from all 625 cells gives their basins of attraction, the sets of starts that end at each peak (fitness landscapes defines them). Under steepest ascent, 238 of the 625 starts (38.1%) end at $C$; under first improvement, only 185 (29.6%). The basins have different shapes because first improvement always prefers whichever direction is scanned first, here up. It follows that direction even when another neighbor is much higher. Averaged over all starts, the two rules cost:
- steepest ascent, 6.62 moves and 30.24 evaluations per climb;
- first improvement, 6.72 moves and 18.88 evaluations per climb.
First improvement pays fewer evaluations per move but has a smaller chance of reaching the best peak. The TSP experiment below measures the same trade-off on a much larger neighborhood. The numbers come from tools/experiments/evolution/hill_climbing_examples.py in the site repository.
Cost per step against number of steps
This section measures the same trade-off when a state has 4,850 neighbors instead of four. The cost of a hill climb is the number of steps times the cost of a step, and the variants trade one against the other.
- Steepest ascent takes the largest improvement available, so it needs few steps. But every step costs a full scan of the neighborhood.
- First-improvement and first-choice take smaller improvements, so they need more steps. But a step ends as soon as an improvement turns up, which early in a climb is almost immediately.
The four variants were run on kroA100 with the 2-opt neighborhood. Each of 30 seeded runs started all four from the same random tour. An evaluation is the computation of one move's change in tour length. First-choice drew moves without replacement, steepest ascent broke ties by move order, and stochastic hill climbing chose uniformly among improving moves.
Example (evaluations by variant). First-choice used the fewest evaluations, by a wide margin, and stochastic hill climbing the most. Medians, with interquartile ranges in parentheses:
| Variant | Steps | Evaluations | Evaluations per step | Final tour above optimum |
|---|---|---|---|---|
| First-improvement | 390 (376 to 407) | 591,039 (505,596 to 692,742) | 1,589 (1,227 to 1,771) | 5.63% (3.43 to 7.59) |
| Steepest ascent | 104 (102 to 108) | 506,825 (499,550 to 527,438) | 4,897 (4,895 to 4,898) | 6.80% (4.56 to 8.79) |
| First-choice | 330 (312 to 342) | 29,974 (27,841 to 32,519) | 92 (84 to 104) | 10.93% (6.09 to 13.47) |
| Stochastic | 329 (314 to 342) | 1,600,500 (1,525,325 to 1,664,762) | 4,865 (4,864 to 4,865) | 8.50% (5.84 to 12.67) |
Several things are visible.
- Steepest ascent took a quarter as many steps as first-improvement but used about as many evaluations, because each of its steps cost the full 4,850. (The ratio is slightly above 4,850 because the per-run ratio counts the final scan, which made no move.)
- First-improvement's cost per step is high for a different reason. It restarts its scan from the first move after every step, and near the end of a climb the improving moves are few and late in the order.
- First-choice looks at moves in random order. It found an improvement after about 92 evaluations per step, and the whole climb cost about one seventeenth of steepest ascent's.
- Stochastic hill climbing combined the worst of both: as many steps as first-choice, at the full cost of steepest ascent.
Cheaper climbs did not give equally good tours. The first-choice tours were the longest, a median of 10.9% above the optimum against 5.6% for first-improvement. The interquartile ranges overlap, and this is one instance, so the ordering of tour quality is suggestive rather than settled.
What is settled is the cost. Per unit of computation, first-choice is far cheaper. That makes it attractive as the inner loop of a method that climbs many times, such as random restarts. The comparison changes with the neighborhood. A larger neighborhood, such as 3-opt, has fewer local optima but costs more per scan. Fast TSP implementations cut the scan cost with candidate lists of each city's nearest neighbors (Lourenço, Martin, and Stützle, 2003). The script is tools/experiments/evolution/hill_climbing.py in the site repository.
One run, step by step
The medians hide the shape of a climb. The figure below follows the four variants through a single run, the first of the 30. All four start from the same random tour of length 175,761, more than eight times the optimum. The horizontal axis counts evaluations on a logarithmic scale, so each variant's curve shows how much computation it spent to reach each tour length.
Steepest ascent makes its first move only after evaluating all 4,850 neighbors, so its curve is flat until then. After that, each move removes the worst remaining pair of edges. The tour shrinks quickly in length per move but slowly per evaluation. To reach twice the optimum length, the variants needed:
- first-choice, 2,010 evaluations;
- first improvement, 144,444;
- steepest ascent, 208,550;
- stochastic hill climbing, 1,139,750.
In this run steepest ascent ended best, at 21,812 (2.49% above the optimum). First improvement ended at 22,383, first-choice at 22,996, and stochastic hill climbing at 23,944. Single runs vary a great deal, which is why the table reports medians over 30.
Every one of these runs stopped at a 2-opt local optimum short of the best tour. The next section sets out the features of a problem that stop a hill climber.
Where hill climbing gets stuck
A hill climber that accepts only strict improvements stops at the first local optimum it reaches. The structure of the fitness landscape decides how often that is a poor place to stop. Russell and Norvig (2020, §4.1.1) name three features: local maxima, plateaus, and ridges.
The first two can be seen together on a one-dimensional example. It follows the spirit of Russell and Norvig's one-dimensional state-space picture, but with numbers that can be checked. The states are the integers $x = 0, 1, \ldots, 60$, and the neighbors of $x$ are $x - 1$ and $x + 1$. The objective $f$ is the piecewise-linear profile drawn below, with integer values from 3 to 21. Later articles return to this one-dimensional example by name.
Strict steepest ascent moves to the higher neighbor while it is strictly higher, and to the left one on a tie. It reaches the global maximum from 17 of the 61 starting points, 27.9%. The other 44 starts are lost to four different features. Each needs a different remedy, as the rest of this section and escaping local optima explain.
A common reading of a stopped hill climber is "it stopped because it found a peak". The three features show that a stop need not be at a peak at all. A shoulder is not a peak, since higher ground is reachable without going down. A ridge point is a peak only for the moves the climber happens to have.
Local maxima. A local maximum is higher than all its neighbors but lower than the global maximum. Every run in the kroA100 table ended at a 2-opt local optimum that was not the global one. On the 8-queens problem, Russell and Norvig's running example, the objective is the number of pairs of queens that attack each other, to be minimized. Steepest descent from a random placement reaches a solution only about 14% of the time. Otherwise it stops, after a climb of only three or four moves, at a board that no single move improves. (Hill climbing on 8-queens and the 8-puzzle reproduces this over 30,000 runs, and finds that 98.6% of these stops are on plateaus rather than strict local minima.)
Plateaus. A plateau is a connected region of equal value (fitness landscapes defines it and the drift it causes). For a hill climber, two kinds are worth distinguishing.
- A flat local maximum has no higher neighbor anywhere on its edge, so no amount of wandering helps.
- A shoulder is a plateau with an uphill edge somewhere, so progress is possible if the search keeps moving.
A strict hill climber stops on both. Allowing sideways moves to neighbors of equal value lets it cross a shoulder. On a flat maximum it would wander forever, so the number of consecutive sideways moves must be capped. The 8-queens problem has many shoulders. Allowing up to 100 consecutive sideways moves raises the success rate of steepest descent from about 14% to about 94%, at the price of longer climbs. (Escaping local optima gives the numbers.)
The one-dimensional example shows both kinds and makes the cap concrete. Here is the idea in one sentence. On a shoulder, sideways moves with random tie-breaking are a random walk, which covers a distance $m$ in about $m^2$ steps.
Its shoulder runs from $x = 20$ to $x = 26$ at height 11, and $x = 27$ is higher. A climber that arrives at $x = 20$ from the left has one neighbor of equal value, $x = 21$. Inside the shoulder it has two, and with random tie-breaking it steps left or right with probability $\tfrac{1}{2}$ each. At $x = 26$ the uphill exit appears. The sideways moves therefore form a symmetric random walk on the seven states 20 to 26, turned back at 20 and ending at 26. (Random Walks and Martingales solves the plateau with an exit at each end as the gambler's ruin problem, its Theorem 1.)
The expected length of the walk. Number the states by their distance $i$ from the left end, so the walk starts at $i = 0$ and ends at $i = m$, with $m = 6$ here. Let $e_i$ be the expected number of steps still needed from $i$. Three facts determine it:
- $e_m = 0$, since the walk has arrived;
- $e_0 = 1 + e_1$, since the only move from the left end is to $i = 1$;
- $e_i = 1 + \tfrac{1}{2}(e_{i-1} + e_{i+1})$ for $0 < i < m$, one step and then either neighbor with probability $\tfrac{1}{2}$.
The expectations are finite. From any state the walk reaches $m$ within $m$ steps with probability at least $2^{-m}$, by stepping right every time. So the chance of still walking after $km$ steps is at most $(1 - 2^{-m})^k$, which falls geometrically.
The formula $e_i = m^2 - i^2$ satisfies all three. The first is immediate, and the second reads $m^2 = 1 + (m^2 - 1)$. For the third,
$$1 + \tfrac{1}{2}\left(m^2 - (i-1)^2 + m^2 - (i+1)^2\right) = 1 + m^2 - i^2 - 1 = m^2 - i^2.$$
No other solution exists. The difference $g_i$ of two solutions satisfies $g_m = 0$, $g_0 = g_1$ and $g_i = \tfrac{1}{2}(g_{i-1} + g_{i+1})$. The last says that consecutive differences $g_{i+1} - g_i$ are all equal, the second says that the first of them is 0, so $g$ is constant, and $g_m = 0$ makes it zero. The walk from the left end therefore takes $e_0 = m^2$ steps on average, here $6^2 = 36$ sideways moves. The script confirms the value by summing the walk's exact distribution.
Propagating that distribution for 100 steps gives a probability of 0.9612 of reaching $x = 26$ within a cap of 100.
On the flat maximum from 45 to 50, by contrast, both edges lead down. The same walk spends the whole budget of 100 moves going back and forth before it stops. With the cap at 100, the probability of reaching the global maximum from a uniformly random start rises from 0.2787 to 0.4527. (The walk was computed with random tie-breaking throughout, so the two valley points $x = 14$ and $x = 42$ now go either way with equal probability.)
Example (a start at $x = 10$). A climber that starts at $x = 10$ does not reach the global maximum, even with up to 100 sideways moves allowed. It climbs to $x = 8$, a strict local maximum: both neighbors are lower, so there is no sideways move to make. Every start from 0 to 13 climbs to $x = 8$ and stops there for the same reason. The 18 starts from 43 to 60, which end on the flat maximum or the edge maximum, are not helped either. Their climbs end where every way out goes down.
Ridges. A ridge is a sequence of local maxima that rises, but in a direction no single move follows. A small example makes the geometry concrete. On the integer grid $0 \le x, y \le 10$, let
$$f(x, y) = (x + y) - 10\,(x - y)^2,$$
with moves that change one coordinate by $\pm 1$. The first term rewards moving up and to the right; the second punishes any distance from the diagonal, heavily. Along the diagonal, $f(k, k) = 2k$, rising from 0 to 20. But from any diagonal point, every move leaves the diagonal, to a cell where $(x - y)^2 = 1$. The four moves give two values:
- raising a coordinate, $f(k + 1, k) = f(k, k + 1) = 2k + 1 - 10 = 2k - 9$;
- lowering one, $f(k - 1, k) = f(k, k - 1) = 2k - 1 - 10 = 2k - 11$.
Both are lower than $2k$. Every diagonal point is therefore a local maximum. A hill climber started at $(0, 0)$ stops at once with $f = 0$, although $f(10, 10) = 20$.
A move along the diagonal, changing both coordinates at once, would climb the ridge directly. The ridge is a property of the objective together with the move set, as all of these features are.
In two dimensions the remedy looks obvious: add the diagonal move. In a problem with thousands of variables, the useful combined moves are not known in advance. Adding all combinations makes the neighborhood too large to scan. This is the general tension in choosing a neighborhood:
- a small one is cheap to scan and has many local optima;
- a large one has fewer local optima and is expensive.
Is there a move set that keeps most of the cheapness of small moves but can still make a large jump? The simplest evolutionary algorithm has one.
The (1+1) EA: a hill climber with a global mutation operator
The simplest evolutionary algorithm differs from a stochastic hill climber in one respect. The $(1+1)$ EA on bitstrings of length $n$ keeps one parent $x$ and creates one child $y$ by flipping each bit independently with probability $1/n$. It replaces $x$ by $y$ if $f(y) \ge f(x)$ (Droste, Jansen, and Wegener, 2002). It is the bitstring counterpart of the $(1+1)$ evolution strategy from the early history of evolutionary computation.
Compare it with randomized local search, which flips exactly one bit chosen uniformly at random and makes the same acceptance test. Randomized local search accepts moves to equal values, which lets it drift across plateaus. Apart from that, it is first-choice hill climbing with sampling with replacement and no stopping rule.
The difference lies in the neighborhood. Randomized local search can reach only the $n$ strings at Hamming distance 1. The mutation operator of the $(1+1)$ EA can produce any string at all. The intuition: each bit flips rarely, so most children differ from the parent in a bit or two, but no particular change is impossible. A particular string at Hamming distance $k$ arises with probability
$$\left(\frac{1}{n}\right)^{k} \left(1 - \frac{1}{n}\right)^{n-k}.$$
The $k$ chosen bits must all flip, each with probability $1/n$, and the other $n - k$ must all stay, each with probability $1 - 1/n$. The product is never zero.
Example (one particular string two bits away). For $n = 100$, the $(1+1)$ EA must produce about 26,800 children, on average, to hit one particular string two bits away. The probability is $(1/100)^2 (99/100)^{98}$, about $3.7 \times 10^{-5}$. Each child is an independent try, so the number of tries is geometric and its mean is the reciprocal of that probability (escaping local optima derives the mean). For comparison:
| Distance $k$ | Probability of one particular string | Expected tries |
|---|---|---|
| 1 | about 0.0037 | about 270 |
| 2 | about $3.7 \times 10^{-5}$ | about 26,800 |
| 3 | about $3.8 \times 10^{-7}$ | about 2,651,000 |
The values are rounded; the script tools/experiments/evolution/hill_climbing_examples.py computes them. About 37% of children, a fraction $(1 - 1/n)^n \approx 1/e$, are exact copies of the parent.
The operator is called global because no string has probability zero. Under it, every state is a neighbor of every other. So in the strict sense of the definition, the $(1+1)$ EA has no local optima except the global ones.
It is tempting to conclude that the $(1+1)$ EA cannot get stuck. It can, in a different currency: what it has instead of local optima is waiting times. If the only improvement on a state lies $k$ bits away, the probability of producing it in one step is at most $n^{-k}$. So the expected wait is at least $n^k$ steps.
Droste, Jansen, and Wegener (2002) made this exact with the functions $\mathrm{Jump}_m$. These rise with the number of ones, except for a gap of width $m$ just below the all-ones optimum. They proved that the expected optimization time of the $(1+1)$ EA on $\mathrm{Jump}_m$ is $\Theta(n^m + n \log n)$. For $m = 1$ that is the $\Theta(n \log n)$ of OneMax. For the trap function, where the gap spans the whole space, it is $\Theta(n^n)$. Randomized local search, by contrast, never crosses a gap of width 2 or more once it reaches the edge of one. Every string with one more one lies in the gap and has lower fitness, so the acceptance test refuses it.
So the $(1+1)$ EA is best read as a stochastic hill climber on a weighted neighborhood. It mostly makes one- or two-bit moves, and occasionally a long jump. Fitness landscapes shows the consequence on NK problems. There, most of the runs that found the global optimum had passed through a local optimum of the one-bit-flip neighborhood on the way. The $(1+1)$ EA also shows why the fitness landscape depends on the algorithm. The same function can have thousands of local optima for randomized local search and none, strictly speaking, for the $(1+1)$ EA.
Hill climbing elsewhere
Hill climbing appears inside many algorithms that are not usually called by that name. K-means is one. Lloyd's algorithm alternates two steps, neither of which can raise the residual sum of squares, and it stops when neither step changes anything. That point is a local minimum of the objective with respect to those two steps, not necessarily the global minimum. The standard remedy is to run k-means from several starting points and keep the best result, which is random-restart hill climbing. (K-means in practice measures how much the start matters on Reuters.) Graph indexes for vector search are another: HNSW answers a query by a greedy walk over a graph of stored vectors, which can stop at a local minimum of the distance to the query.
Some evolutionary algorithms also apply a hill climber to each offspring before it competes. Eiben and Smith (2015, ch. 10) treat these hybrids as memetic algorithms, in which local search refines what the evolutionary search finds (natural selection for computer scientists asks which rule of inheritance they bend).
What we have learned
Hill climbing is fully specified only when its pivot rule, tie-breaking, and stopping rule are. The pivot rule changes more than cost: on the grid it moved the start at $(17, 4)$ from the global peak to a lower one. On kroA100 it traded evaluations against tour quality, with first-choice about seventeen times cheaper than steepest ascent. Every variant stops at a local optimum. A stop can mean a strict local maximum, a plateau, or a ridge that no single move follows. The one-dimensional example lost 44 of its 61 starts to these features. The $(1+1)$ EA has no local optima in the strict sense, but it pays for distant improvements with long waits.
Hill climbing is fast, and on smooth problems it is enough. Its weakness is that it never accepts a worse state, so it ends wherever the first local optimum lies. Escaping local optima shows how a search can accept worse states, or start over, without giving up what it has found. It does so with sideways moves, restarts, simulated annealing, tabu search, iterated local search, and finally the population of an evolutionary algorithm.
References
- Croes, G. A. (1958). A method for solving traveling-salesman problems. Operations Research, 6(6), 791–812. record
- Droste, S., Jansen, T., and Wegener, I. (2002). On the analysis of the (1+1) evolutionary algorithm. Theoretical Computer Science, 276(1–2), 51–81. record · 5 pages
- Eiben, A. E., and Smith, J. E. (2015). Introduction to Evolutionary Computing, 2nd ed., chapter 10. Springer. record · 35 pages
- Lin, S. (1965). Computer solutions of the traveling salesman problem. Bell System Technical Journal, 44(10), 2245–2269. record
- Lourenço, H. R., Martin, O. C., and Stützle, T. (2003). Iterated local search. In F. Glover and G. A. Kochenberger (Eds.), Handbook of Metaheuristics, 320–353. Kluwer Academic Publishers. record · 2 pages
- Reinelt, G. (1991). TSPLIB: A traveling salesman problem library. ORSA Journal on Computing, 3(4), 376–384. record
- Russell, S., and Norvig, P. (2020). Artificial Intelligence: A Modern Approach, 4th ed., section 4.1. Pearson. record · 6 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 9 revisions