Genetic Algorithms infographic
Phase 7 · Algorithm 30 of 40

🧬 Genetic Algorithms

Evolutionary optimization — searching a solution space by breeding better answers, generation after generation.

🎯 Core Concept

A Genetic Algorithm (GA) evolves a population of candidate solutions toward higher fitness using the mechanics of natural selection: the fittest survive, reproduce, and mutate. Instead of following a gradient, it explores the search space in parallel — useful when the landscape is rugged, discontinuous, or has no usable derivative. 💡 Mental model: “Survival of the fittest as a search engine — keep the good, mix them, jitter a little, repeat.”

🔑 Key Components

Chromosome

An encoded candidate solution — often a bitstring or vector of ‘genes’ representing the parameters being optimized.

Fitness Function

Scores how good each solution is. It defines the objective and steers the whole search — design it carefully.

Crossover

Recombines two parents at a cut point to produce offspring, blending traits and enabling large exploratory jumps.

Mutation

Randomly perturbs genes with small probability. Injects diversity and prevents premature convergence to a local optimum.

⚙️ How It Works

  1. Initialize a random population of chromosomes.
  2. Evaluate each individual with the fitness function.
  3. Select fitter parents (tournament or roulette-wheel — higher fitness, higher odds).
  4. Crossover selected parents to breed a new generation of offspring.
  5. Mutate offspring slightly, then repeat until fitness plateaus or a generation budget is hit.

🌎 Real-World Applications

Neural architecture search Scheduling & timetabling Route & logistics optimization Antenna & circuit design Hyperparameter tuning Game strategy evolution

🧪 Checkpoint Questions

1. Why does a GA maintain a whole population rather than improving a single solution like gradient descent?

Hint: think about escaping local optima and exploring a rugged, non-differentiable landscape in parallel.

2. What breaks if you set the mutation rate to zero — and what breaks if you set it too high?

Hint: zero mutation kills diversity (premature convergence); too much turns evolution into random search.

3. When would you reach for a GA instead of gradient descent or a convex solver?

Hint: no usable gradient, discrete/combinatorial variables, or a highly multimodal objective.