ArticleslgStudy

computer science

Hill climbing

Hill climbing is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Hill climbing rather than just read about it. In short: In numerical analysis, hill climbing is a mathematical optimization technique which belongs to the family of local search. It is an iterative algorithm that starts with an arbitrary solution to a problem, then attempts to find a better solution by making an incremental change to the solution.

Hill climbing — main illustration
Hill climbing — illustration

Key takeaways

  • Hill climbing belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Hill climbing to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Hill climbing from memory before moving on to harder problems.

Reference excerpt

In numerical analysis, hill climbing is a mathematical optimization technique which belongs to the family of local search. It is an iterative algorithm that starts with an arbitrary solution to a problem, then attempts to find a better solution by making an incremental change to the solution. If the change produces a better solution, another incremental change is made to the new solution, and so on until no further improvements can be found. For example, hill climbing can be applied to the travelling salesman problem. It is easy to find an initial solution that visits all the cities but will likely be very poor compared to the optimal solution. The algorithm starts with such a solution and makes small improvements to it, such as switching the order in which two cities are visited. Eventually, a much shorter route is likely to be obtained. Hill climbing finds optimal solutions for convex problems – for other problems it will find only local optima (solutions that cannot be improved upon by any neighboring configurations), which are not necessarily the best possible solution (the global optimum) out of all possible solutions (the search space). Examples of algorithms that solve convex problems by hill-climbing include the simplex algorithm for linear programming and binary search. To attempt to avoid getting stuck in local optima, one could use restarts (i.e. repeated local search), or more complex schemes based on iterations (like iterated local search), or on memory (like reactive search optimization and tabu search), or on memory-less stochastic modifications (like simulated annealing). The relative simplicity of the algorithm makes it a popular first choice amongst optimizing algorithms. It is used widely in artificial intelligence, for reaching a goal state from a starting node. Different choices for next nodes and starting nodes are used in related algorithms. Although more advanced algorithms such as simulated annealing or tabu search may give better results, in some situations hill climbing works just as well. Hill climbing can often produce a better result than other algorithms when the amount of time available to perform a search is limited, such as with real-time systems, so long as a small number of increments typically converges on a good solution (the optimal solution or a close approximation). At the other extreme, bubble sort can be viewed as a hill climbing algorithm (every adjacent element exchange decreases the number of disordered element pairs), yet this approach is far from efficient for even modest N, as the number of exchanges required grows quadratically. Hill climbing is an anytime algorithm: it can return a valid solution even if it's interrupted at any time before it ends.

Mathematical description Hill climbing attempts to maximize (or minimize) a target function f ( x ) {\displaystyle f(\mathbf {x} )} , where x {\displaystyle \mathbf {x} } is a vector of continuous and/or discrete values. At each iteration, hill climbing will adjust a single element in x {\displaystyle \mathbf {x} } and determine whether the change improves the value of f ( x ) {\displaystyle f(\mathbf {x} )} . (Note that this differs from gradient descent methods, which adjust all of the values in x {\displaystyle \mathbf {x} } at each iteration according to the gradient of the hill.) With hill climbing, any change that improves f ( x ) {\displaystyle f(\mathbf {x} )} is accepted, and the process continues until no change can be found to improve the value of f ( x ) {\displaystyle f(\mathbf {x} )} . Then x {\displaystyle \mathbf {x} } is said to be "locally optimal". In discrete vector spaces, each possible value for x {\displaystyle \mathbf {x} } may be visualized as a vertex in a graph. Hill climbing will follow the graph from vertex to vertex, always locally increasing (or decreasing) the value of f ( x ) {\displaystyle f(\mathbf {x} )} , until a local maximum (or local minimum) x m {\displaystyle x_{m}} is reached.

… excerpt ends here. Continue reading the full article.

Illustrations

Hill climbing: A surface with only one maximum. Hill-climbing techniques are well-suited for optimizing over such surfaces, and will converge to the global maximum.
A surface with only one maximum. Hill-climbing techniques are well-suited for optimizing over such surfaces, and will converge to the global maximum.
Hill climbing: A surface with two local maxima. (Only one of them is the global maximum.) If a hill-climber begins in a poor location, it may converge to the lower maximum.
A surface with two local maxima. (Only one of them is the global maximum.) If a hill-climber begins in a poor location, it may converge to the lower maximum.
Hill climbing: Despite the many local maxima in this graph, the global maximum can still be found using simulated annealing. Unfortunately, the applicability of simulated annealing is problem-specific because it relies on finding lucky jumps that improve the position. In such extreme examples, hill climbing will most probably produce a local maximum.
Despite the many local maxima in this graph, the global maximum can still be found using simulated annealing. Unfortunately, the applicability of simulated annealing is problem-specific because it relies on finding lucky jumps that improve the position. In such extreme examples, hill climbing will most probably produce a local maximum.
Hill climbing: A ridge
A ridge

Worked examples

Example 1 — a first encounter with Hill climbing

Start with the simplest possible case. Write down what Hill climbing claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Hill climbing before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Hill climbing ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Hill climbing

In research
Hill climbing appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Hill climbing in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Hill climbing is common in secondary-school and first-year university syllabi. It links to neighbouring topics Metaheuristics, Search algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Hill climbing outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Hill climbing” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Hill climbing in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Hill climbing means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Hill climbing out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Hill climbing in simple terms?

In numerical analysis, hill climbing is a mathematical optimization technique which belongs to the family of local search. It is an iterative algorithm that starts with an arbitrary solution to a problem, then attempts to find a better solution by making an incremental change to the solution.

Why does Hill climbing matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Hill climbing?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Hill climbing.

Tags

  • Metaheuristics
  • Search algorithms

Keep exploring