3.5 Building K-maps
Why this matters
Grouping on a K-map only works if the map was filled correctly, and filling it is where most mistakes happen: one row in the wrong cell turns a good grouping into a wrong circuit. The fill itself is mechanical once you see what the layout is for. This section builds that skill, so that the grouping in the next section can start from a map you trust.
Learning goals
Section titled “Learning goals”- Explain why the labels of a K-map run in Gray order instead of counting order.
- Draw the two-, three- and four-variable layouts this book uses, with bit labels or with brackets.
- Fill a map from a truth table, placing every row in its own cell, including across the jump from 011 to 100.
- Read a truth table back from a filled map.
- Move a function between the two three-variable layouts.
Intuition first
Section titled “Intuition first”A K-map is a truth table cut into a grid. It has one cell for every row of the table, so it holds exactly the same information, and nothing is added or lost. The only decision is where each row goes, and the rule is simple: two cells that touch must be neighbors in the sense of Definition 3.4.4, meaning their input patterns differ in exactly one input. That is what lets your eye find the pairs that the uniting theorem can merge.
If you program, picture reshaping a one-dimensional array into a two-dimensional one. The data is the same, and only the indexing changes. The analogy breaks at one point: an ordinary reshape keeps the original order, so that the index counts up along each row. A K-map does not. Its column labels are in an order chosen so that neighbors touch, and so counting order has to be given up.
Gray order
Section titled “Gray order”Take two inputs. In counting order the patterns are 00, 01, 10, 11. Laid side by side in that order, 01 would touch 10, and those two patterns differ in both inputs, so they are not neighbors. Meanwhile 01 and 11 are neighbors and are not next to each other. Counting order puts the wrong things together.
A list of bit patterns is in Gray order when each pattern differs from the next in exactly one bit. For two bits, one such list is 00, 01, 11, 10.
This list has one more useful property: its last pattern, 10, differs from its first, 00, in one bit as well. So if the list is laid out along an edge of a map, the two ends are also neighbors, and the edges of the map wrap around. Every K-map in this book labels its columns and its rows in this order.
A Karnaugh map (K-map) is a grid with one cell for each row of a truth table. The cell's column and row are labeled with input patterns in Gray order, and the cell holds the function's output for the pattern formed by its column label and its row label. Cells that touch, including across opposite edges, are neighbors.
With four inputs, every cell touches four others: the cells to its left, right, above and below, counting the wrap around each edge. Those are exactly its four neighbors. On a three-variable map, which has two rows, a cell touches only three: the cells to its left and right, counting the wrap, and the cell in the other row. Above and below are the same cell there, and it is one neighbor. That is again exactly the number of neighbors a pattern of three inputs has.
The layouts this book uses
Section titled “The layouts this book uses”The layout says which inputs run along the top and which down the side. This book uses these:
- Two variables: B along the top (the columns) and A down the side (the rows).
- Three variables: the columns are AB and the rows are C. A second arrangement puts the columns at BC and the rows at A. The first is the default in this book, and the second is always called the alternate layout.
- Four variables: the columns are AB and the rows are CD.
Some textbooks put the variables on the other edges, and then their maps are not the same as these ones, even for the same function. When you compare a map with one from another source, read the axis labels first.
| B=0 | B=1 | |
|---|---|---|
| A=0 | 1 | 1 |
| A=1 | 0 | 1 |
Description: A two-by-two Karnaugh map with columns B and rows A, with bit labels.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 0 | 0 | 0 | 1 |
| C=1 | 1 | 1 | 0 | 1 |
Description: A Karnaugh map with four columns labeled with the bit pairs of AB in Gray order and two rows labeled with the bits of C, plus brackets that mark where A, B and C are 1.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 1 | 0 | 1 | 0 |
| CD=01 | 0 | 0 | 0 | 1 |
| CD=11 | 1 | 0 | 1 | 0 |
| CD=10 | 0 | 1 | 0 | 0 |
Description: A Karnaugh map with four columns labeled with the bit pairs of AB in Gray order and four rows labeled with the bit pairs of CD in Gray order, plus brackets that mark where A, B, C and D are 1.
The brackets are an alternative to writing the bit labels. A bracket along an edge marks the columns or rows in which a variable is 1, and the variable is 0 everywhere else. You can use either style, or both. In the four-variable map, A has a bracket over the two right-hand columns, B has one under the two middle columns, C has one beside the two bottom rows, and D has one beside the two middle rows. In the three-variable map, A and B have the same brackets, and C has one beside the bottom row.
Filling a map from a truth table
Section titled “Filling a map from a truth table”The method is the same for every layout, and it never involves walking down the table filling cells in order. Instead, for each row of the table:
- Split the input pattern into the part that labels the columns and the part that labels the rows.
- Find the column whose label matches the first part, and the row whose label matches the second part.
- Write the row's output in the cell where they meet.
Use the function F from Example 3.4.1, shown again in Figure 3.5.4. For the row where A, B and C are 0, 0, 1, the columns part is AB = 00 and the rows part is C = 1, so its output goes in the cell at row C=1, column AB=00. For the row 0, 1, 1 it is AB = 01 and C = 1, the cell at row C=1, column AB=01.
| A | B | C | F |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 0 |
Description: A truth table of F with inputs A, B and C; the rows where A, B and C are 0 0 1, 0 1 1, 1 0 0 and 1 0 1 are highlighted.
Every 1 of the table becomes a cell of the map. Figure 3.5.5 draws each of them as a group of its own, and the legend under the map says where each one sits.
F =
- single cell: row 1, column 00
- single cell: row 1, column 01
- single cell: row 0, column 10
- single cell: row 1, column 10
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 0 | 0 | 0 | 1 |
| C=1 | 1 | 1 | 0 | 1 |
Groups drawn:
- not A and not B and C: single cell in row C=1, column AB=00; 1 cell.
- not A and B and C: single cell in row C=1, column AB=01; 1 cell.
- A and not B and not C: single cell in row C=0, column AB=10; 1 cell.
- A and not B and C: single cell in row C=1, column AB=10; 1 cell.
Description: A three-variable Karnaugh map with four single-cell outlines, one for each row of the truth table where F is 1.
Notice that the four terms written under the map are the four products of the on-set sum of products from Section 3.4, one for each outlined cell. A map can show that sum directly. It does not yet simplify anything: that is what groups of several cells do, in the next section.
The jump from 011 to 100
Section titled “The jump from 011 to 100”The table counts in binary: after 011 comes 100. The map labels do not count: after the column labeled 01 comes the column labeled 11, and only then the column labeled 10. So the rows of the table whose first two inputs are 10 belong at the far right end of the map, and the rows whose first two inputs are 11 belong in the third column. A map filled by walking down the table and across the columns goes wrong exactly there.
The table row 0, 1, 1 goes in the bottom cell of the column labeled 01. After it comes the table row 1, 0, 0. Where does that row go?
In F, the table rows 0, 1, 1 and 1, 0, 0 are both 1, and they sit on consecutive lines. On the map, the first is the cell at row C=1, column AB=01 and the second is the cell at row C=0, column AB=10. Consecutive lines of the table land in different rows of the map, and the second cell is in the last column, with only the column labeled 11 between it and the first. Figure 3.5.5 shows both.
The safe habit is the three steps above. Say the first two inputs, find that label on the map, and never rely on "the next column over".
Reading a map back
Section titled “Reading a map back”A filled map holds the same table, and you can recover the table by reversing the steps: for every cell, join its column label and its row label into an input pattern, and the cell's value is that pattern's output. A count is a quick check on either direction. A function with five 1s in its table has five 1s on its map.
The alternate three-variable layout
Section titled “The alternate three-variable layout”In the alternate layout the columns are BC and the rows are A. The table order of the columns is again 00, 01, 10, 11 and the map order 00, 01, 11, 10, so the jumps move. The pair of rows that goes wrong in the first layout, 011 and 100, is no longer special: in the alternate layout the jumps are from 001 to 010 and from 101 to 110.
The rows of the table are the same, and so is the function. Only the cells move.
The majority function is 1 when at least two of A, B and C are 1. Figure 3.5.6 draws it in the default layout and Figure 3.5.7 in the alternate layout, each with every 1 outlined as a cell of its own.
F =
- single cell: row 1, column 01
- single cell: row 1, column 10
- single cell: row 0, column 11
- single cell: row 1, column 11
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 0 | 0 | 1 | 0 |
| C=1 | 0 | 1 | 1 | 1 |
Groups drawn:
- not A and B and C: single cell in row C=1, column AB=01; 1 cell.
- A and not B and C: single cell in row C=1, column AB=10; 1 cell.
- A and B and not C: single cell in row C=0, column AB=11; 1 cell.
- A and B and C: single cell in row C=1, column AB=11; 1 cell.
Description: A three-variable Karnaugh map with columns AB and rows C and four single-cell outlines, one for each row of the truth table where the majority function is 1.
F =
- single cell: row 0, column 11
- single cell: row 1, column 01
- single cell: row 1, column 10
- single cell: row 1, column 11
| BC=00 | BC=01 | BC=11 | BC=10 | |
|---|---|---|---|---|
| A=0 | 0 | 0 | 1 | 0 |
| A=1 | 0 | 1 | 1 | 1 |
Groups drawn:
- not A and B and C: single cell in row A=0, column BC=11; 1 cell.
- A and not B and C: single cell in row A=1, column BC=01; 1 cell.
- A and B and not C: single cell in row A=1, column BC=10; 1 cell.
- A and B and C: single cell in row A=1, column BC=11; 1 cell.
Description: A three-variable Karnaugh map with columns BC and rows A and four single-cell outlines, one for each row of the truth table where the majority function is 1.
The table row where A, B and C are all 1 is a single cell in both layouts, but its place differs: it is at row C=1, column AB=11 in the default layout and at row A=1, column BC=11 in the alternate one.
The two layouts also draw the same group differently. The two table rows where A and B are both 1 are neighbors in either layout. In the default layout they form a vertical pair, and in the alternate layout a horizontal pair. The term they give, , does not depend on the layout.
A four-variable map
Section titled “A four-variable map”With four inputs the same two steps happen twice: the pair AB picks a column and the pair CD picks a row, and both labels are in Gray order, so the jump occurs on each axis. In the table the last two inputs count 00, 01, 10, 11, and the rows of the map run 00, 01, 11, 10. The same is true for the first two inputs and the columns.
Let F be 1 when the number written by the four inputs A, B, C and D, with A as the high bit, is a multiple of 3. That makes six rows of the table 1.
| A | B | C | D | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 | 1 |
Description: A sixteen-row truth table of F with inputs A, B, C and D; the rows 0 0 0 0, 0 0 1 1, 0 1 1 0, 1 0 0 1, 1 1 0 0 and 1 1 1 1 are highlighted.
Take the row 1, 0, 0, 1. Its columns part is AB = 10 and its rows part is CD = 01, so its output goes in the cell where the column labeled 10 meets the row labeled 01. The row 0, 0, 1, 1 has AB = 00 and CD = 11, so its output is in the first column and the third row of labels.
F =
- single cell: row 00, column 00
- single cell: row 11, column 00
- single cell: row 10, column 01
- single cell: row 01, column 10
- single cell: row 00, column 11
- single cell: row 11, column 11
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 1 | 0 | 1 | 0 |
| CD=01 | 0 | 0 | 0 | 1 |
| CD=11 | 1 | 0 | 1 | 0 |
| CD=10 | 0 | 1 | 0 | 0 |
Groups drawn:
- not A and not B and not C and not D: single cell in row CD=00, column AB=00; 1 cell.
- not A and not B and C and D: single cell in row CD=11, column AB=00; 1 cell.
- not A and B and C and not D: single cell in row CD=10, column AB=01; 1 cell.
- A and not B and not C and D: single cell in row CD=01, column AB=10; 1 cell.
- A and B and not C and not D: single cell in row CD=00, column AB=11; 1 cell.
- A and B and C and D: single cell in row CD=11, column AB=11; 1 cell.
Description: A four-variable Karnaugh map with six single-cell outlines, one for each row of the truth table where F is 1.
No two of these six cells touch. Neighbors differ in one bit, so their values as numbers differ by 1, 2, 4 or 8, and none of those is a multiple of 3. So this map has nothing to group, and each 1 stays a term of four variables. A different function would have groups, and the next section is about those.
Course conventions
Section titled “Course conventions”How CSE 369 writes this
In CSE 369 the K-map layouts are these: for two variables, columns B and rows A; for three variables, columns AB and rows C, with an alternate layout of columns BC and rows A; for four variables, columns AB and rows CD. Labels are in Gray order, and a bracket along an edge marks where a variable is 1. The lecture warns that most mistakes in filling a three-variable map come from the jump between the table rows 011 and 100, and for the alternate layout between 001 and 010 and between 101 and 110.
Pitfalls
Section titled “Pitfalls”Common pitfall
- Filling the columns in table order. The rows that start 1, 0 belong in the column labeled 10, at the right end, and not in the third column.
- Labeling the columns in counting order, 00 01 10 11. Cells that touch must differ in one bit, so the labels have to run 00 01 11 10.
- Swapping the axes: reading the layout with C on the columns, or with CD on the columns of a four-variable map. Look at which inputs the labels name before reading a cell.
- Mixing up the two three-variable layouts. The cell for the same table row is in a different place in the alternate layout, and the jumps move.
- Skipping the count. The number of 1s on the map must equal the number of 1s in the table.
Check your understanding
Section titled “Check your understanding”Take the quiz (5 questions)
The function whose map is in Figure 3.5.9 is 1 on how many of the sixteen rows?
Which product term belongs to the single cell for the table row 1, 0, 0, 1 of that function?
Which list is the right order for the column labels of a K-map?
In the default three-variable layout, a table row has A = 1 and B = 1. In which column of the map does it go?
A map in the default three-variable layout has five 1s. How many rows of its truth table have output 1?
Exercises
Section titled “Exercises”A function of two inputs A and B is 1 on the rows 00, 01 and 11, and 0 on the row 10. Draw its map with A on the rows and B on the columns.
Hint
Solution
There are four cells, one for each row. The row 10 has A = 1 and B = 0, so its 0 goes in the cell where the row labeled 1 meets the column labeled 0. The other three cells are 1.
| B=0 | B=1 | |
|---|---|---|
| A=0 | 1 | 1 |
| A=1 | 0 | 1 |
Description: A two-by-two Karnaugh map with columns B and rows A, with one 0 and three 1s.
The table below is for a function F. Fill in its map in the default layout, with columns AB and rows C, and check that the numbers of 1s agree.
| A | B | C | F |
|---|---|---|---|
| 0 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 |
| 0 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Description: A truth table of F with inputs A, B and C. F is 1 on five of the eight rows.
Hint
Solution
The table has five rows where F is 1: 000, 010, 100, 101 and 111. Each one goes where its AB column meets its C row. The rows 100 and 101 have AB = 10, so they go in the column labeled 10, one in each row of the map, and the row 111 has AB = 11 and C = 1, so it goes where the column labeled 11 meets the row labeled 1. The map has five 1s, as the table does.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 1 | 1 | 0 | 1 |
| C=1 | 0 | 0 | 1 | 1 |
Description: A three-variable Karnaugh map in the default layout with five 1s.
Draw the function of the previous exercise in the alternate layout, with columns BC and rows A. Say which of its five 1s keep the same column label as in the default layout and which do not.
Hint
Solution
In the alternate layout each row of the table is placed by its B and C values for the column and its A value for the row. The five 1s are 000, 010, 100, 101 and 111.
| BC=00 | BC=01 | BC=11 | BC=10 | |
|---|---|---|---|---|
| A=0 | 1 | 0 | 0 | 1 |
| A=1 | 1 | 1 | 1 | 0 |
Description: A three-variable Karnaugh map with columns BC and rows A and five 1s.
The table is the same in both layouts, so each of the five 1s is still a cell, and only its place changes. In the default layout a row's column label is its first two inputs, and in the alternate layout it is its last two. A row therefore keeps its column label only when its first two inputs equal its last two, which happens for 000 and 111 and for no other row. Among the five 1s: 000 has column label 00 in both layouts; 010 has 01 and then 10; 100 has 10 and then 00; 101 has 10 and then 01; 111 has 11 in both. So the rows 000 and 111 keep their column label, and the other three do not.
Read the truth table back from this map. List the input rows where F is 1, and then describe the function in a sentence.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 0 | 1 | 1 |
| CD=01 | 1 | 1 | 0 | 0 |
| CD=11 | 1 | 1 | 0 | 0 |
| CD=10 | 0 | 0 | 1 | 1 |
Description: A four-variable Karnaugh map with eight 1s.
Hint
Solution
The map has eight 1s. Reading each as column label then row label, the rows of the table where F is 1 are 0001, 0011, 0101, 0111, 1000, 1010, 1100 and 1110.
| A | B | C | D | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 1 |
| 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Description: A sixteen-row truth table with eight highlighted rows where F is 1.
In the highlighted rows, A and D always differ: A is 0 and D is 1 in the first four, and A is 1 and D is 0 in the last four. B and C take every value. So F is 1 exactly when one of A and D is 1 and the other is 0.
A student filled in the map below from the table in the earlier exercise by copying the table rows into the cells from left to right, in counting order. Say what is wrong with it, and say which cells differ from the correct map.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 1 | 1 | 1 | 0 |
| C=1 | 0 | 0 | 1 | 1 |
Description: A three-variable Karnaugh map in the default layout with five 1s.
Hint
Solution
The student put the rows with AB = 11 under the column labeled 10, and the rows with AB = 10 under the column labeled 11. That is the jump the lecture warns about: counting order puts 11 after 10, and the map puts it before. The correct map is the one below, and it differs from the student's in the top cells of those two columns. In the student's map the cell at column 10, row C=0 holds a 0 and the cell at column 11, row C=0 holds a 1, and in the correct map it is the other way round. The cells in the row C=1 of the two columns hold 1 in either order for this function, so they do not show the mistake.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| C=0 | 1 | 1 | 0 | 1 |
| C=1 | 0 | 0 | 1 | 1 |
Description: A three-variable Karnaugh map in the default layout with five 1s.
Let F be 1 when the two-bit number AB (A is the high bit) is greater than the two-bit number CD. List the table rows where F is 1, and draw the four-variable map.
Hint
Solution
The number AB = 00 is never greater than CD, so it contributes nothing. AB = 01 is greater only than CD = 00, which gives the row 0100. AB = 10 is greater than CD = 00 and CD = 01, which gives 1000 and 1001. AB = 11 is greater than 00, 01 and 10, which gives 1100, 1101 and 1110. That is six rows.
| A | B | C | D | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 |
Description: A sixteen-row truth table with six highlighted rows where F is 1.
| AB=00 | AB=01 | AB=11 | AB=10 | |
|---|---|---|---|---|
| CD=00 | 0 | 1 | 1 | 1 |
| CD=01 | 0 | 0 | 1 | 1 |
| CD=11 | 0 | 0 | 0 | 0 |
| CD=10 | 0 | 0 | 1 | 0 |
Description: A four-variable Karnaugh map with six 1s.