Genetic Algorithms: Evolution in Code — lecture notes
Selection, crossover and mutation: watch a population of bit strings evolve towards a perfect solution, generation by generation.
0:001. Introduction

Nature solves hard design problems through evolution. Genetic algorithms borrow that idea: breed better and better solutions over many generations.
0:092. The loop

Start with a population of random candidate solutions. Score each one with a fitness function. Select the fitter ones as parents. Combine their genes with crossover. Add small random mutations. Then repeat.
0:233. Watching evolution

Here each individual is a string of sixteen bits, and fitness simply counts the ones. Green cells are ones. Watch generation by generation as selection, crossover and mutation push the population towards all ones. The chart on the right tracks the best fitness, and by generation sixteen it finds the perfect string of sixteen ones.
0:464. The operators

Crossover combines good pieces from two parents into one child. Mutation randomly flips a bit now and then. Crossover exploits what already works. Mutation keeps exploring.
0:585. Applications

Genetic algorithms are useful when the search space is huge and there is no neat formula. Timetables, engineering designs, tuning other algorithms, and even evolving game strategies.
1:106. Recap

To recap. A population evolves. Fitness decides who reproduces. Crossover mixes good ideas and mutation explores new ones. Great for big, messy search problems.
Key takeaways
- Genetic algorithms evolve a population of candidate solutions.
- A fitness function decides which candidates become parents.
- Crossover combines parents; mutation adds random variation.
- They suit large search spaces without a neat mathematical solution.
Check yourself
- What does the fitness function do?
Show answer
Scores how good each candidate is — Fitness measures quality and drives selection.
- Which operator mainly keeps diversity in the population?
Show answer
Mutation — Random mutations introduce new variation.
- In the OneMax example, what is the best possible fitness for 16 bits?
Show answer
16 — Fitness counts the 1s, so all sixteen 1s is optimal.
Go deeper
- Genetic Algorithms and Evolutionary Computation · The AI Lecture Hall
- Swarm Intelligence: Particle Swarm Optimisation and Ant Colony Optimisation · The AI Lecture Hall
© 2026 Janin A Apurba, CSE, AUST · Advanced ICT Officer, CNRS-UNHCR. All rights reserved. Notes for the animated lecture at https://ai-in-motion.vercel.app/watch/genetic-algorithms.html