AI in Motion

Artificial IntelligenceIntermediate1:21 video6 chapters

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.

▶ Watch the animated lecture

0:001. Introduction

Introduction — Genetic Algorithms: Evolution in Code

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

0:092. The loop

The loop — Genetic Algorithms: Evolution in Code

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

Watching evolution — Genetic Algorithms: Evolution in Code

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

The operators — Genetic Algorithms: Evolution in Code

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

Applications — Genetic Algorithms: Evolution in Code

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

Recap — Genetic Algorithms: Evolution in Code

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

  1. What does the fitness function do?
    Show answer

    Scores how good each candidate is — Fitness measures quality and drives selection.

  2. Which operator mainly keeps diversity in the population?
    Show answer

    Mutation — Random mutations introduce new variation.

  3. 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

© 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