Edexcel International Advanced Level Computer Science, point 15.4.2
Definition
A Karnaugh map (K-map) is a grid that shows a Boolean function's truth table in a layout that makes it easy to simplify. Cells that differ in only one variable are placed next to each other, so groups of adjacent 1s can be read off as simpler terms.
Function and why needed
- Simplifying a Boolean expression by algebra (15.4.1) needs skill and can miss the simplest form. A K-map gives a visual, reliable method, for up to about four variables.
- A simpler expression means fewer logic gates (cheaper, faster, lower power).
Notation (Appendix 2): AND is , OR is , NOT is .
Structure of a K-map
Number of cells
A function of variables has cells, one for each row of the truth table.
| Variables | Cells | Layout |
|---|---|---|
| 2 | 4 | 2 × 2 |
| 3 | 8 | 2 × 4 |
| 4 | 16 | 4 × 4 |
Gray code ordering
The row and column labels are in Gray code: only one bit changes between neighbouring labels: 00, 01, 11, 10 (not 00, 01, 10, 11). This is what makes neighbouring cells differ in only one variable.
Layout for 3 variables (rows A, columns BC):
(m0 to m7 are the row numbers of the truth table: for example m6 is A=1, B=1, C=0.)
Layout for 4 variables (rows AB, columns CD):
Method
- Draw the grid and label the rows and columns in Gray code.
- Fill in the 1s (and 0s) from the truth table or expression.
- Circle groups of adjacent 1s, following the rules below.
- For each group, write a term containing only the variables that don't change within the group.
- OR (+) the terms together.
Grouping rules
- Groups must be rectangles (or squares), with sides of 1, 2 or 4 cells, so the size is a power of 2: 1, 2, 4, 8, 16.
- Only adjacent cells (horizontally or vertically, not diagonally).
- Groups should be as large as possible (larger groups give simpler terms).
- Use as few groups as possible, but cover every 1.
- Groups can overlap (a 1 can be in more than one group).
- The map wraps round: the left and right edges are neighbours, and so are the top and bottom edges (and the four corners).
- Never group 0s (unless simplifying the complement).
Reading a group
Look at which variables stay the same across the group:
- A variable that is always 1 in the group appears as itself ().
- A variable that is always 0 appears as its inverse ().
- A variable that changes (both 0 and 1) is dropped.
A bigger group drops more variables: a group of 2 drops 1 variable, a group of 4 drops 2, a group of 8 drops 3.
Example 1: two variables
.
| B=0 | B=1 | |
|---|---|---|
| A=0 | 0 | 1 |
| A=1 | 0 | 1 |
One vertical group of two 1s (the column B = 1): A changes (dropped), B stays 1. .
Example 2: three variables
Truth table: for minterms 0, 1, 2, 3 and 6 (that is, for all four combinations of B and C, and ).
- Group 1: the whole top row (4 cells). A = 0 throughout; B and C both change. Term: .
- Group 2: the pair m2 and m6 (the right-hand column, both rows). A changes; B = 1, C = 0 throughout. Term: .
(Group 2 uses m2 again, which is allowed, because that makes the group bigger.)
Example 3: four variables, with wrap-around
for minterms 0, 2, 8, 10, 5, 7, 13 and 15.
- Group 1: the four corners (m0, m2, m8, m10), which are neighbours because the map wraps both ways. A and C change, but B = 0 and D = 0 throughout. Term: .
- Group 2: the central 2 × 2 block (m5, m7, m13, m15). A and C change, but B = 1 and D = 1. Term: .
(This is B XNOR D.) Without the K-map, the expression has 8 minterms of 4 variables each.
Example 4: from an expression
Simplify (2 variables).
| B=0 | B=1 | |
|---|---|---|
| A=0 | 1 | 1 |
| A=1 | 0 | 1 |
- Group 1: the top row (A = 0): term .
- Group 2: the right column (B = 1): term .
Check by algebra: . ✓
Benefits
- Quick and visual, less error-prone than long algebra.
- Finds the simplest sum-of-products form for small functions.
- Easy to check the result.
Drawbacks
- Practical only up to about 4 (maybe 5 or 6) variables.
- Needs care with Gray code, wrap-around and grouping (common mistakes).
- Doesn't show the working for the exam unless you write the terms for each group.
- Several equally good answers can exist.
Worked example
Task: simplify the function when is 001, 011, 101 or 111 (that is, C = 1, whatever A and B are).
- One group of four (the two middle columns, both rows): A changes (dropped), B changes (dropped), C = 1 throughout.
Check: is 1 exactly when C is 1. ✓ From four three-variable terms to one letter.
Exam tip: label the map in Gray code (00, 01, 11, 10). Group in powers of 2, as large as possible, and use wrap-around. For each group, write down only the variables that stay the same (inverted if they stay at 0). Show each group clearly and write the final OR of terms.
Check yourself
Why are K-map labels in Gray code?
Only one variable changes between neighbouring cells, so adjacent 1s can be grouped to eliminate a variable.
What sizes of group are allowed?
Rectangles of 1, 2, 4, 8 or 16 cells (powers of 2), which may wrap round the edges.
How many variables are dropped by a group of 4 cells?
Two.
Can groups overlap?
Yes, a 1 can be in more than one group, which is often needed to make groups as large as possible.
Why is the K-map's result a simpler expression?
Larger groups drop more variables, so each term has fewer variables and fewer terms are needed, meaning fewer logic gates.