Karnaugh maps
Minimising a Boolean function on a Karnaugh map: Gray-code layout, groups and wrap-around, prime and essential prime implicants, don't cares, products of sums, and the situations where the answer is not unique.
Why it exists
Algebraic simplification works only when you can see the pattern. A Karnaugh map (K-map) turns the search for patterns into a picture. The truth table is arranged on a grid so that cells that differ in exactly one variable are physically next to each other. Two adjacent 1-cells then merge into a term with one variable fewer (), four cells into a term with two fewer, and so on. GATE questions give you a function (as a truth table, minterms or an expression) and ask for the minimal SOP or POS, the number of prime implicants, the number of essential prime implicants, or how don't cares change the answer. Maps are practical for up to 4 variables (5 with some care).
Prerequisites
You need minterm and maxterm numbering from SOP, POS, minterms and maxterms and the combining law from Boolean algebra.
Precise definitions
Layout. A map for variables has cells, one per minterm. The labels along each side are in Gray-code order (00, 01, 11, 10), not in binary order, so that neighbouring labels differ in one bit. The cell in row label and column label is the minterm whose binary index is followed by . For four variables the rows are and the columns ; for three variables the rows are (0, 1) and the columns (00, 01, 11, 10). With a 5th variable use two 4-variable maps (for and ); a cell is also adjacent to the cell in the same position on the other map.
Adjacency. Two cells are adjacent if their minterms differ in exactly one variable. On the map, neighbours across the edges count: the left and right edges are adjacent, the top and bottom edges are adjacent, and so the four corners are all neighbours of each other.
Group (implicant). A rectangle of 1-cells (or don't cares) whose number of cells is a power of two (1, 2, 4, 8, 16) and whose sides are aligned to the Gray-code layout; wrap-around is allowed, diagonals and L-shapes are not. A group of cells is a product term with literals: the variables that take both values inside the group are dropped, and each variable that is constant is kept (true form if constant 1, complemented if constant 0).
Prime implicant. A group that cannot be enlarged (it is not contained in a larger group). Essential prime implicant. A prime implicant that covers at least one 1-cell no other prime implicant covers; it must be in every minimal SOP. A 1 covered by only one prime implicant is what marks it as essential.
Minimal SOP (as defined on the forms page): the fewest product terms, and among those the fewest literals. Procedure:
- Fill in the map from the truth table or minterm list.
- Find all prime implicants (the largest possible groups).
- Select all the essential prime implicants and mark the cells they cover.
- Cover the remaining 1s with as few extra prime implicants as possible, preferring the largest.
- Read each group as a product term and OR them. Groups may overlap.
Don't cares. A cell marked X may be put in a group if it helps make the group larger, and it need not be covered. A don't care is never required in the answer.
Product of sums. Group the 0s (and the don't cares) of instead. Each group of 0s gives a sum term: a variable that is constant 0 over the group appears in true form, a variable that is constant 1 appears complemented. The AND of the sum terms is the minimal POS of . (Equivalently, minimise as an SOP and complement the result with De Morgan.)
Non-uniqueness. A function can have several different minimal SOPs of the same cost. This happens when no prime implicant is essential for some cells, as in the cyclic case below.
Limits. For or 6 a map becomes unreadable. The tabular method (Quine-McCluskey) does the same job algorithmically.
How it works
Each animation fills in the map, then adds groups one at a time, the essential prime implicants first, and finally reads the expression. The map labels are Gray-coded, the number in the corner of each cell is its minterm index, and the coloured dots show which groups cover a cell. Every group, every cell and every term is produced by an exact minimiser (not typed in), and re-derived in the tests.
Three variables: F = sum m(0, 2, 4, 5, 6): Fill in the map
Exact minimiser, not typed| A\BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 10 | 01 | 03 | 12 |
| 1 | 14 | 15 | 07 | 16 |
Small number = minterm index. X = don't care. Row and column labels are in Gray-code order.
Groups so far (product terms)
None yet.
Step 1
Each cell is one row of the truth table. The row and column labels are in Gray-code order, so any two neighbouring cells, including cells on opposite edges, differ in exactly one variable.
Worked examples
EX 1Three variables: F = sum m(0, 2, 4, 5, 6)
EasyThe animation above is this function.
Step 1. The four cells 0, 2, 4, 6 all have . They are adjacent in a block ( and vary, is constant 0), so they form one group of 4 reading .
Step 2. Cell 5 has a neighbour 4. The group has , constant and varying, so it reads .
Result. . Both groups are essential: cell 2 can only be covered by and cell 5 only by .
The program below checks the result against the minterm list on all rows.
#include <stdio.h>
static int f3(int m) { return m == 0 || m == 2 || m == 4 || m == 5 || m == 6; }
static int g3(int m) {
int a = (m >> 2) & 1, b = (m >> 1) & 1, c = m & 1;
return !c || (a && !b);
}
static int corners(int m) { return m == 0 || m == 2 || m == 5 || m == 7 || m == 8 || m == 10 || m == 13 || m == 15; }
static int xnor_bd(int m) {
int b = (m >> 2) & 1, d = m & 1;
return b == d;
}
static int sop1(int m) {
int a = (m >> 3) & 1, c = (m >> 1) & 1, d = m & 1;
return (!a && d) || (c && d);
}
static int sop2(int m) {
int a = (m >> 3) & 1, b = (m >> 2) & 1, c = (m >> 1) & 1, d = m & 1;
return (!a && !b) || (c && d);
}
int main(void) {
int bad = 0;
for (int m = 0; m < 8; m++) bad += f3(m) != g3(m);
printf("C' + AB' differs from the sum m(0,2,4,5,6) on %d of 8 rows\n", bad);
bad = 0;
for (int m = 0; m < 16; m++) bad += corners(m) != xnor_bd(m);
printf("B'D' + BD differs from the corner function on %d of 16 rows\n", bad);
printf("A'D + CD and A'B' + CD differ on rows:");
for (int m = 0; m < 16; m++)
if (sop1(m) != sop2(m)) printf(" %d", m);
printf("\n");
int ones[] = {1, 3, 7, 11, 15};
int ok = 1;
for (int i = 0; i < 5; i++) ok = ok && sop1(ones[i]) && sop2(ones[i]);
printf("both give 1 on every required minterm: %d\n", ok);
return 0;
}C' + AB' differs from the sum m(0,2,4,5,6) on 0 of 8 rows
B'D' + BD differs from the corner function on 0 of 16 rows
A'D + CD and A'B' + CD differ on rows: 0 2 5
both give 1 on every required minterm: 1EX 2Four corners and the centre
MediumFour corners and the centre: F = sum m(0, 2, 5, 7, 8, 10, 13, 15): Fill in the map
Exact minimiser, not typed| AB\CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 10 | 01 | 03 | 12 |
| 01 | 04 | 15 | 17 | 06 |
| 11 | 012 | 113 | 115 | 014 |
| 10 | 18 | 09 | 011 | 110 |
Small number = minterm index. X = don't care. Row and column labels are in Gray-code order.
Groups so far (product terms)
None yet.
Step 1
Cells 0, 2, 8 and 10 sit in the four corners. They look far apart, but the labels show they are neighbours around the edges: 0000 and 0010 differ only in D, and 0000 and 1000 only in A.
Step 1. Cells 0, 2, 8, 10 are the four corners. Over the edges they are mutual neighbours: 0000 and 0010 differ only in , 0000 and 1000 only in . Together and vary while and are constant, so the group of 4 reads .
Step 2. Cells 5, 7, 13, 15 form a block in the middle ( and vary, and ), reading .
Result. , which is (XNOR of and ). Both prime implicants are essential, and the program above confirms the result on all 16 rows. A group never needs to be a visible rectangle: it is a rectangle on a surface where the opposite edges are glued together.
EX 3Don't cares: F = sum m(1, 3, 7, 11, 15) + d(0, 2, 5)
MediumDon't cares: F = sum m(1, 3, 7, 11, 15) + d(0, 2, 5): Fill in the map
Exact minimiser, not typed| AB\CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | X0 | 11 | 13 | X2 |
| 01 | 04 | X5 | 17 | 06 |
| 11 | 012 | 013 | 115 | 014 |
| 10 | 08 | 09 | 111 | 010 |
Small number = minterm index. X = don't care. Row and column labels are in Gray-code order.
Groups so far (product terms)
None yet.
Step 1
Cells marked X may be treated as 1 or 0, whichever makes bigger groups. They need not be covered.
Step 1. covers the column of cells 3, 7, 15, 11 (, ). It is the only group that covers cell 11, so it is essential.
Step 2. The remaining 1 is cell 1. It can be covered by (cells 1, 3, 5, 7, using the don't care 5) or by (cells 0, 1, 2, 3, using the don't cares 0 and 2). Both groups have two literals.
Result. or . These are two minimal answers (2 terms, 4 literals). The program shows they differ only on rows 0, 2, 5, the don't cares, so both are correct for the specification. Without the don't cares the best SOP would be , with 5 literals.
EX 4Product of sums: group the zeros
MediumProduct of sums: group the 0s of F = prod M(4, 5, 6, 7, 12, 13): Fill in the map
Exact minimiser, not typed| AB\CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 10 | 11 | 13 | 12 |
| 01 | 04 | 05 | 07 | 06 |
| 11 | 012 | 013 | 115 | 114 |
| 10 | 18 | 19 | 111 | 110 |
Small number = minterm index. X = don't care. Row and column labels are in Gray-code order.
Groups so far (sum terms)
None yet.
Step 1
For a product of sums, group the 0s instead. Each group of 0s gives a sum term that is 0 exactly on that group: the variables that are 1 appear complemented.
, so on those six rows.
Step 1. The zeros 4, 5, 6, 7 form a group of 4 with and constant ( and vary). For a sum term, a variable that is constant 0 appears in true form and one that is constant 1 appears complemented: .
Step 2. The zeros 4, 5, 12, 13 form a second group of 4 with and constant ( and vary; the rows 01 and 11 are neighbours and so are the columns 00 and 01). It reads . Cells 4 and 5 are in both groups, which is allowed.
Result. . Check: when and (rows 4 to 7) or when and (rows 4, 5, 12, 13): exactly the six zeros.
EX 5No essential prime implicant: two minimal answers
GATE levelTwo equally good answers: F = sum m(0, 1, 2, 5, 6, 7): Fill in the map
Exact minimiser, not typed| A\BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 10 | 11 | 03 | 12 |
| 1 | 04 | 15 | 17 | 16 |
Small number = minterm index. X = don't care. Row and column labels are in Gray-code order.
Groups so far (product terms)
None yet.
Step 1
Each cell is one row of the truth table. The row and column labels are in Gray-code order, so any two neighbouring cells, including cells on opposite edges, differ in exactly one variable.
. The six 1-cells form a ring: each is covered by exactly two of the six prime implicants , , , , , (cells 0 and 1, 0 and 2, 1 and 5, 2 and 6, 5 and 7, 6 and 7). No cell is covered by only one, so there are no essential prime implicants.
Any three non-overlapping groups of two cover the ring, and there are exactly two minimal answers: and , each with 3 terms and 6 literals. The animation shows one of them. A question that asks for "the" minimal expression will list only one of the options as correct, and the other must not appear.
EX 6Counting prime implicants
GATE level| Function | prime implicants | essential |
|---|---|---|
| (3 variables) | 2 (, ) | 2 |
| corners function (4 variables) | 2 (, ) | 2 |
| 3 (, , ) | 1 () | |
| 6 | 0 | |
| parity | 4 | 4 |
For the parity function every 1-cell is isolated, so each minterm is a prime implicant on its own and is essential.
EX 7SOP is cheaper than POS for AB + CD
GATE levelFor the minimal SOP has 2 terms, 4 literals. Its minimal POS is : 4 sum terms, 8 literals. Whether the SOP or POS form is cheaper depends on the function. If a question asks for the cheaper two-level form, find both (group the 1s, then the 0s) and compare their literal or gate counts.
Cheat box
Cheat box
- Gray-code labels: 00, 01, 11, 10. Edges wrap: the four corners of a 4-variable map are adjacent.
- Group sizes 1, 2, 4, 8, 16 (powers of two), rectangles only. A group of cells drops variables (term has literals).
- SOP from 1s: constant 1 gives the variable, constant 0 its complement. POS from 0s: constant 0 gives the variable, constant 1 its complement.
- Essential prime implicant: covers a 1 nobody else covers. It is in every minimal answer.
- Don't cares: use them only to enlarge groups; never cover a don't care on its own.
- Overlap is allowed. The answer is not always unique (cyclic case: 2 answers, 0 essentials).
- Parity (XOR of variables): checkerboard, no groups bigger than 1, terms.
- 5 variables: two 4-variable maps, with matching cells adjacent. Beyond that, use the tabular method.
Traps and GATE patterns
Connections
Builds on
Unlocks
Across subjects
No cross-subject links yet.
Within this subject
A K-map starts from the canonical forms in SOP, POS, minterms and maxterms and its answer feeds the gate networks of logic gates and the whole flow in combinational design. Two adjacent prime implicants that are not overlapped can cause a glitch; that is the subject of static hazards. The tabular method is the same idea in a form a program can carry out.
PYQs
5 previous year questions from your book. I re-solved each one myself (5 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider a Boolean function F with the following min-term expression: F(P, Q, R, S) = Σm(1, 2, 3, 4, 5, 7, 10, 12, 13, 14) Which of the following options is/are the minimal sum-of-products expression(s) of F?
- (a)P ̅S+ QR ̅ + P ̅Q ̅R+ Q ̅RS ̅
- (b)P ̅S+ QR ̅ + P ̅QR ̅ + PRS ̅
- (c)P ̅S+ QR ̅ + PQS ̅ + PRS ̅
- (d)P ̅S+ QR ̅ + PQS ̅ + Q ̅RS ̅
Consider the following 4-variable Boolean function F(A, B, C, D) = Σm(0, 1, 2, 3, 8, 9, 10, 11) Consider A as MSB, D as LSB. Which one of the following options represents the minimal sum of products form for the above function? Note: + is OR operation, · is AND operation, ' is NOT operation
- (a)A' + B' + C' + D'
- (b)B'
- (c)A'·B' + A·B
- (d)A'
The number of min-terms after minimizing the following Boolean expression is ________. [D' + AB' + A'C + AC'D + A'C'D]'.
Let f(w,x,y,z) = Σ (0,4,5,7,8,9,13,15). Which of the
following expressions are NOT equivalent to f?
P: x'y'z' + w'xy' + wy'z + xz
Q: w'y'z' + wx'y' + xz
R: w'y'z' + wx'y' + xyz + xy'z
DIGITAL LOGIC
S: x'y'z' + wx'y' + w'y- (a)P only
- (b)Q and S
- (c)R and S
- (d)S only
The boolean function for a combinational circuit with four inputs is represented by the following Karnaugh map. Which of the product terms given below is an essential prime implicant of the function?
- (a)QRS
- (b)PQS
- (c)PQ'S'
- (d)Q'S'
Self-check
Question 1
Minimise over .
Show answerHide
All four cells have and , vary, so one group of 4 reads . .
Question 2
Minimise over .
Show answerHide
All eight cells have , varies in and , cover all four values, so , and are dropped in a group of 8 reading . .
Question 3
How many prime implicants and how many essential prime implicants does the three-variable parity function have?
Show answerHide
4 prime implicants (the four minterms , , , ) and all 4 are essential.
Question 4
A group of 8 cells on a four-variable map reads a term with how many literals?
Show answerHide
, so three variables are dropped and the term has literal.
Revision card
One-screen revision
- Gray-code labels, wrap-around edges (corners are neighbours). Groups: rectangles of cells; a group drops variables.
- Steps: fill, find prime implicants, take essential ones, cover the rest with the fewest groups, read terms.
- SOP groups 1s (constant 1 gives the variable). POS groups 0s (constant 0 gives the variable).
- Don't cares only help enlarge groups. The answer may not be unique (ring of six has 0 essentials, 2 answers).
- Parity has no groups larger than one cell.
References
- ·Mano and Ciletti, Digital Design, 5th ed., Chapter 3 Gate-Level Minimization (the map method, product-of-sums simplification, don't-care conditions)
- ·Kohavi and Jha, Switching and Finite Automata Theory, Chapter 4 Minimization of switching functions
Verification
Every group, term and result in the animations comes from an exact minimiser (Quine-McCluskey prime implicants plus an exhaustive minimum cover, scripts/dl_minimize.py). tests/dl-traces.test.ts re-derives each term from the group's cells independently and checks the Gray-code labels, rectangle shape, power-of-two size and coverage. scripts/enum-checks/dl_forms.py checks minimal covers for all 256 three-variable functions, 300 random four-variable functions with don't cares (also against a second exhaustive search), the prime implicant counts and essential sets quoted here, and that every cube is a rectangle on the map. The C program is compiled and run by npm run verify:c. Textbook chapter titles are from memory; the independent second pass has not been run, so the page stays draft. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (conversions, signed ranges and flags, IEEE 754 fields and custom formats, Boolean identities and counts, K-map groups, adder carries, BCD correction, flip-flop conversions, counter sequences and T equations, state reduction, Quine-McCluskey rounds and covers, floating-point alignment and rounding); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)