Skip to content
CoreSource checked

Genetic Algorithm

Evolves a population of candidate solutions through selection and variation.

Quick Facts

Compact metadata for implementation and discovery.

Category
Optimization
Difficulty
Intermediate
Family
Evolutionary Search
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
8
Code example
Not ready
Visualization
Ready

Overview

A Genetic Algorithm scores candidate solutions, keeps stronger ones, and creates new candidates by crossover and mutation.

Core Concepts

objective functionmetaheuristic searchcandidate populationrandom samplingevolutionary searchiterative improvementstopping rule

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(gpf)

Average

O(gpf)

Worst

O(gpf)

Space

O(p)

When to Use

  • Use Genetic Algorithm when you need to maintain many candidate solutions.
  • Use it for search spaces with many local optima with inputs like initial population.
  • Use it when you can define a score, objective, constraint, or feasibility test clearly.
  • Use it when the Evolutionary Search tradeoff is acceptable for the problem size.

When Not to Use

  • Avoid it when repeatability is required but seeds and random sources are not controlled.
  • Avoid it when the objective is noisy or changing and the algorithm assumes stable feedback.
  • Avoid it when the required output is not best candidate solution.

What It Does

  • Maintains many candidate solutions
  • Combines and mutates candidates over generations

Use Cases

  • Search spaces with many local optima
  • Design optimization
  • Parameter tuning

Inputs

  • Initial population
  • Fitness function
  • Selection and mutation rules

Outputs

  • Best candidate solution

Key Formulas (1)

Fitness-proportional selection

P(candidatei) = fitnessi / ∑(fitnessall)
P(candidate_i) = fitness_i / sum(fitness_all)

Gives fitter candidates a larger chance of being selected as parents.

Pseudocode

  1. 1.Create an initial population
  2. 2.Evaluate each candidate with a fitness function
  3. 3.Select candidates to reproduce
  4. 4.Create new candidates with crossover and mutation
  5. 5.Repeat for many generations

Canonical Example

Input
objective = minimize (x - 3)^2, start = x = 0
Output
x moves toward 3
Explanation
Genetic Algorithm: The algorithm repeatedly improves a candidate solution according to the objective.

Implementation Notes

  • Keep the input contract explicit: Initial population; Fitness function; Selection and mutation rules.
  • Use this step as the implementation spine: Create an initial population.
  • Then preserve the next state change: Evaluate each candidate with a fitness function.
  • Thread a seedable random source through the implementation for repeatable tests.
  • Log objective values across iterations so regressions and stalled progress are visible.

Common Pitfalls

  • Genetic Algorithms need representation and mutation choices that fit the problem.
  • Stopping after one good-looking result without checking convergence or constraints.
  • Returning best candidate solution without handling empty, invalid, or boundary inputs.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show candidate solutions changing and improving across generations.

Genetic Algorithm mechanism walkthrough step 1 of 5x₀x₁x₂x*
Step 1 of 5: Create an initial population
population-evolution

Notes

Genetic Algorithm operates in O(gpf) time and O(p) space within the Evolutionary Search family. Key governing relation: P(candidate_i) = fitness_i / sum(fitness_all). Often compared with Simulated Annealing and K-Means.

Sources (1)

What each reference supports for this entry.

Genetic Algorithms in Search, Optimization, and Machine Learning

Book

Reference book for genetic algorithm selection, crossover, and mutation mechanisms.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Conceptual neighborDifferential Evolution

Differential evolution uses evolutionary mutation and selection ideas for continuous vectors.

Both are population-based optimizers for difficult search spaces.

Related Algorithms

Tags

OptimizationMetaheuristicPopulation BasedStochastic