core Estimated learning time: 6 h

4.10 Local search and optimisation

You can apply hill climbing, simulated annealing, local beam search and a genetic algorithm to an optimisation problem, and say which failure each one answers.

Before:01. Mathematics for Machine Learning02. Python — Basics to Advanced

The problem changes shape here: stop wanting the path, start wanting the state — which lets the whole search tree be thrown away in favour of one current state, and makes astronomically large spaces workable. Hill climbing fails in three named ways — local maxima, ridges, plateaux — and simulated annealing, beam search and genetic algorithms are each an answer to a failure. Solving n-queens with every method and comparing costs is the exercise that makes the trade-offs concrete.

Work through these

  • Explain the shift from finding a path to finding a state

    Some problems do not care how you got there, only where you end up, and that changes what an algorithm needs to remember. Dropping the path is what makes these methods usable on enormous spaces.

  • Read a state-space landscape and write an objective function for it

    Picturing the possible states as a landscape whose height is the quality of each one, and writing the function that gives that height. Getting the objective right matters more than the search method.

  • Run hill climbing and diagnose its three failures: local maxima, ridges and plateaux

    Always stepping to a better neighbour is simple and gets stuck three characteristic ways: at a false peak, on a narrow ridge, and on a flat region. Recognising which one you are in tells you what to do next.

  • Apply simulated annealing, and say why accepting a worse move on purpose works

    Accepting a worse move with a probability that falls over time lets the search escape false peaks early and settle later. The physical analogy it is named after makes the schedule intuitive.

  • Run local beam search with k states

    Keeping several candidate states and spreading effort among them, which is more robust than one search and cheaper than many independent ones. The number of states carried is the tuning knob.

  • Apply a genetic algorithm: population, fitness, selection, crossover, mutation

    Treating candidate solutions as a population that reproduces, with fitter members more likely to contribute and occasional random change. It is a general-purpose method with a distinctive vocabulary.

  • Solve n-queens with each method and compare what they cost

    Applying each method to the same classic puzzle makes their costs directly comparable. It is the exercise that stops these methods being four names on a list.

Sign in to keep your progress.

Free resources

Links last checked 29 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.