Simulated Annealing
Probabilistic local search that accepts worse moves with a probability decreasing over time (temperature). Escapes local optima.
Visualization
Interactive visualization for Simulated Annealing
Simulated Annealing:
- • Probabilistic optimization
- • Accepts worse solutions initially
Interactive visualization with step-by-step execution
Implementation
1function simulatedAnnealing(f: (x:number)=>number, start: number, T0=1.0, cooling=0.995, iters=10000): number {
2 let x = start, fx = f(x), T = T0;
3 const randStep = () => (Math.random() - 0.5);
4 for (let k = 0; k < iters; k++) {
5 const xn = x + randStep();
6 const fn = f(xn);
7 if (fn > fx || Math.exp((fn - fx) / T) > Math.random()) { x = xn; fx = fn; }
8 T *= cooling; if (T < 1e-9) break;
9 }
10 return x;
11}Deep Dive
Theoretical Foundation
Simulated annealing is a probabilistic local search inspired by metallurgy. It accepts worse moves with probability exp(Δ/T), where T is a temperature decreased by a cooling schedule, enabling escape from local optima.
Complexity
Time
O(iter)
O(iter)
O(iter)
Space
O(1)
Applications
Industry Use
Combinatorial optimization (TSP, scheduling)
VLSI layout
Network design
Use Cases
Related Algorithms
Binary Search
Binary Search is one of the most efficient searching algorithms with O(log n) time complexity. It works on sorted arrays by repeatedly dividing the search space in half, eliminating half of the remaining elements with each comparison. This divide-and-conquer approach makes it exponentially faster than linear search for large datasets.
Linear Search
Linear Search, also known as Sequential Search, is the simplest searching algorithm that checks each element in a list sequentially until the target element is found or the end is reached. Despite its O(n) time complexity, it's the only option for unsorted data and remains practical for small datasets or when simplicity is crucial.
Jump Search
Jump Search is an efficient algorithm for sorted arrays that combines the benefits of linear and binary search. Instead of checking every element (linear) or dividing the array (binary), it jumps ahead by fixed steps of √n and then performs linear search within the identified block. This approach achieves O(√n) time complexity, making it faster than linear search while being simpler than binary search for certain applications.
Interpolation Search
Interpolation Search is an improved variant of binary search specifically optimized for uniformly distributed sorted arrays. Instead of always checking the middle element, it estimates the target's position based on the target value relative to the range of values, similar to how humans search a phone book. Achieves O(log log n) average time for uniformly distributed data, significantly faster than binary search's O(log n).