> For the complete documentation index, see [llms.txt](https://www.mlcompendium.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.mlcompendium.com/machine-learning/genetic-algorithms-and-genetic-programming.md).

# Genetic Algorithms & Genetic Programming

[**What is the difference?**](https://stackoverflow.com/questions/3819977/what-are-the-differences-between-genetic-algorithms-and-genetic-programming) **Genetic programming and genetic algorithms are very similar. They are both used to evolve the answer to a problem, by comparing the fitness of each candidate in a population of potential candidates over many generations.**<br>

**Each generation, new candidates are found by randomly changing (mutation) or swapping parts (crossover) of other candidates. The least 'fit' candidates are removed from the population. - peterjwest**<br>

![](https://lh4.googleusercontent.com/yPOIDc7UzG8oMQ4p5QiO4igfI0BToXt2GhQBRz2hVflRVFNw9dw88RP5qsXF3ZM5O7f_ytYT9ZGXXjqmeq5Et1UGi8jFZ2qPEfQsauYfrF1U0Qan2qSRThXNdvki2ZSG59BpWsK8)

**Genetic algorithms (GA) are search algorithms that mimic the process of natural evolution, where each individual is a candidate solution: individuals are generally "raw data" (in whatever encoding format has been defined).**

**Genetic programming (GP) is considered a special case of GA, where each individual is a computer program (not just "raw data"). GP explore the algorithmic search space and evolve computer programs to perform a defined task.**

**johnIdol**<br>

![](https://lh3.googleusercontent.com/ueNhmSzZnl2VlTs44mnsdqeEckZvZ87jMhGY1bRAX8uuj9EW_m5BbXKpR70o1hv-yKX1z5_NGA4rHWzvkbPi2YtQSzTPvAqbPNRObNtPjHoWvnf9z_HYoYTG27iy0iAB6_Lnc5hi)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.mlcompendium.com/machine-learning/genetic-algorithms-and-genetic-programming.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
