local search and metaheuristics
Imagine you are dropped somewhere in a foggy mountain range at night and told to reach the highest peak, but you can only feel the ground right around your feet. A natural plan: always step uphill, toward whichever neighboring spot is higher, and stop when every neighbor is lower. That is local search (hill climbing): start with some candidate solution, repeatedly move to a slightly better neighbor, and halt at a local best. It is a general-purpose way to attack hard optimization problems when finding the true optimum is infeasible — you settle for 'good enough, found fast'.
The fatal flaw of plain hill climbing is obvious in the foggy-mountain picture: you reach the top of whatever small hill you happened to start on — a LOCAL optimum — and get stuck, even if a far higher peak (the GLOBAL optimum) lies just across a valley you refuse to descend into. Metaheuristics are clever strategies layered on top of local search to escape such traps. Simulated annealing borrows from cooling metal: it sometimes accepts a WORSE move, with a probability that starts high (allowing wild exploratory downhill steps early) and shrinks over time as a 'temperature' parameter cools, so it can climb out of valleys at first and then settle. Genetic algorithms keep a whole population of candidate solutions, 'breed' new ones by mixing pieces of good parents (crossover) and randomly tweaking them (mutation), letting survival-of-the-fittest steer the population toward better regions. Other examples include tabu search (forbid recently-visited states to avoid cycling) and random restarts (try many starting points).
These methods matter because countless real optimization problems — scheduling, circuit layout, vehicle routing, neural-network architecture, protein folding — are NP-hard, with search spaces too vast for exact methods, yet need a usable answer now. Metaheuristics are flexible, easy to apply to almost any problem where you can define neighbors and a quality score, and often find excellent solutions fast. The honest caveats, which matter a great deal: these methods come with NO guarantee — they may return a poor local optimum and you usually cannot tell how far from optimal you are; their performance depends heavily on tuning (temperature schedules, mutation rates, neighborhood design) and on luck (the random seed); and despite biological or physical names, they are heuristics, not proofs — for problems where a provable guarantee exists, an approximation algorithm is usually the better, more honest choice.
Solving TSP by local search: start with any tour, then repeatedly try a '2-opt' move (remove two edges, reconnect the tour the other way) and keep it if the tour gets shorter. Plain hill climbing stops at a local optimum. Simulated annealing occasionally accepts a LONGER tour early on — with probability exp(-increase/temperature) — to escape that trap, then 'cools' to refine. No guarantee of optimality, but usually a strong tour, fast.
Hill climbing gets stuck at local optima; annealing/genetics escape by sometimes moving downhill.
Metaheuristics give NO optimality guarantee and you usually cannot bound how far off you are; results hinge on tuning and the random seed. Biological/physical names (annealing, evolution) are metaphors, not proofs. When a provable bound exists, prefer an approximation algorithm.