> 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/predictive-ml/genetic-algorithms-and-genetic-programming.md).

# Genetic Algorithms & Genetic Programming

Genetic algorithms and genetic programming are easy to confuse, because both evolve an answer instead of fitting one. The short version is that GA evolves parameters and GP evolves programs or expressions. The page first shows what the two share, in peterjwest's words, and then what separates them, in johnIdol's.

The evolutionary idea also shows up elsewhere in the book. The same notes are in [Learning Classifier Systems](/predictive-ml/learning-classifier-systems.md), [ML Systems](/deep-learning/meta-learning.md#ml-systems), and [NEURO EVOLUTION (GA/GP based)](/deep-learning/other-architectures.md#neuro-evolution-gagp-based).

The question itself comes from the Stack Overflow thread [What is the difference?](https://stackoverflow.com/questions/3819977/what-are-the-differences-between-genetic-algorithms-and-genetic-programming), and the first answer starts with what the two have in common. 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. 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. That answer is by peterjwest, and the figure below draws the same loop.

<figure><img src="https://83674056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgd48oS5_duTKOVE_Et%2Fuploads%2Fgit-blob-cf9c07be323d2ada6f026eba07dd2d1ea52f567f%2Fgimg-437170434e60.png?alt=media" alt=""><figcaption><p>Genetic algorithms and genetic programming.</p></figcaption></figure>

Once the shared loop is clear, the difference is what a single individual is. 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. That distinction is johnIdol's answer in the same thread, and the second figure shows GP sitting inside GA.

<figure><img src="https://83674056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Mgd48oS5_duTKOVE_Et%2Fuploads%2Fgit-blob-49f0e29f4361d6e3203b3c77ee8f7f8cc19bcdac%2Fgimg-b6658c7c8951.png?alt=media" alt=""><figcaption><p>Genetic programming as a special case of GA.</p></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.mlcompendium.com/predictive-ml/genetic-algorithms-and-genetic-programming.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
