The second example – a genetic algorithm
Genetic algorithms are adaptive heuristic search algorithms based on the natural selection principles use to generate good solutions to optimization and search problems. They work with possible solutions to a problem named individuals or phenotypes. Each individual has a representation formed by a set of properties named chromosomes. Normally, the individuals are represented by a sequence of bits, but you can choose the representation that better fits your problem.
You also need a function to determine whether a solution is good or bad named fitness function. The main objective of the genetic algorithm is to find a solution that maximizes or minimizes that function.
The genetic algorithm starts with a set of possible solutions to the problem. This set of possible solutions is named the population. You can generate this initial set randomly or use some kind of heuristic function to obtain better initial solutions.
Once you have the initial population...