liveBook · Manning

Binary representation

As explained in Grokking AI Algorithms, Second Edition

Binary encoding represents solution components using binary values such as zero for exclusion and one for inclusion.

Binary representation encodes each solution component as 0 or 1. In a selection problem, 0 means excluded and 1 means included, turning a complete candidate into a fixed-length bit string. section 4.4 section 4.5

Use binary representation when:

  • The decision for each component is naturally yes/no or on/off, such as selecting items for a knapsack. section 4.4 section 4.5
  • You want compact chromosomes and potentially fast computation using primitive values. section 4.5
  • Choose another encoding when solutions require precise decimal values, item quantities, or ordered sequences. section 4.5 section 5.6

A knapsack chromosome

For 26 available items, create a 26-character chromosome. At each position, write 0 to leave the corresponding item out or 1 to include it. A mutation then selects a gene and flips its value: 1 becomes 0, while 0 becomes 1. section 4.5 section 4.15

Figure 4.11 Binary-encoding the Knapsack Problem
04_11

A visual mapping between knapsack items and their binary gene positions makes the fixed-length representation easy to inspect. section 4.4

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Defines chromosomes and bit meanings, demonstrates mutation, and stops short of detailed alternative encoding mechanisms.
Examples
Uses knapsack item selection, a nine-word phrase, 26-item chromosomes, and single-gene bit-string mutation.
What it assumes
Assumes basic solution-selection reasoning while teaching chromosome, gene, allele, genotype, and phenotype terminology.
What you can do after
Apply it to encode yes-or-no solution choices and implement single-gene mutation by flipping bits.
How it connects
Connects chromosomes, genes, alleles, genotypes, phenotypes, fitness, mutation, real-value encoding, and permutation encoding.

Also explained in

Compare how 6 books explain binary representation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.