For example, a simple fitness function might interpret the genes of an organism as the value of x in a complicated equation. The natural-selection process could then be tuned to prefer organisms that generate an output near zero, so that the survivors would eventually produce a solution to the equation. In this assignment, we will create a program that uses a genetic algorithm to find approximate square roots of integers. Although it is simplified compared to a production implementation, the program demonstrates the basic outline and capabilities of a genetic algorithm. Mutation involves selecting a gene site and modifying it in some fashion, usually by replacing it with another gene.
Mutation is very rare both in real life and in genetic algorithms.
Crossover is the most important process in generating new organisms. Real genetic algorithms usually generate two children in this process, and may splice at more than one point, but we'll simplify things in our implementation. As in real life, there is some randomness, so that a somewhat unfit organism has a chance of surviving even when a more fit one is discarded. Because we will not have time to implement an entire genetic algorithm, much of the code has been provided for you. An organism will be represented entirely by its gene sequence, which in turn will be represented using a singly linked list.