Sub topic 9
Grouping cells in a K-map
This chapter assumes you can already draw a 4-variable K-map with Gray-code row and column labels (rows AB, columns CD, both ordered 00, 01, 11, 10). It also assumes you can convert a minterm number to its binary value. Here you will learn which groups of 1s are legal, how to read a product term from a group, and the mistakes that cost marks in GATE.
Why grouping works
Two cells that are neighbours on the map differ in exactly one variable. For example, m2 (0010) and m3 (0011) differ only in D. By the identity xy + xy' = x, the two minterms merge into one term without D. A group of 2^k cells merges the same way and removes k variables. Grouping is that identity applied repeatedly, with the map showing which minterms can merge.
The legal groups
A group for SOP minimization must satisfy all of these:
- It contains only 1s (or don't-cares, covered in a later chapter).
- Its size is a power of two: 1, 2, 4, 8, or 16.
- It is a rectangle of adjacent cells. Adjacency wraps around the edges.
The map is a torus. The left column is adjacent to the right column, and the top row is adjacent to the bottom row. As a result, the four corners (m0, m2, m8, m10) form a legal quad.
| Group size | Variables eliminated | Literals in the term (4 variables) |
|---|---|---|
| 1 cell | 0 | 4 |
| 2 cells | 1 | 3 |
| 4 cells | 2 | 2 |
| 8 cells | 3 | 1 |
| 16 cells | 4 | 0 (the function is constant 1) |
Bigger groups give fewer literals, so you always want the largest legal groups.
Reading a term from a group
Look at the row and column labels covered by the group. A variable that keeps the same value across the whole group stays in the term. A variable that takes both values drops out. A constant 1 gives the plain letter, and a constant 0 gives the complemented letter.
Worked example 1: corners and center
Take F(A,B,C,D) = Σm(0,2,5,7,8,10,13,15).
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 1 (m0) | 0 | 0 | 1 (m2) |
| 01 | 0 | 1 (m5) | 1 (m7) | 0 |
| 11 | 0 | 1 (m13) | 1 (m15) | 0 |
| 10 | 1 (m8) | 0 | 0 | 1 (m10) |
- The corners {0,2,8,10} form a quad. A and C change, while B=0 and D=0 stay fixed. The term is B'D'.
- The center {5,7,13,15} forms a quad. A and C change, while B=1 and D=1 stay fixed. The term is BD.
So F = BD + B'D', which is XNOR(B, D). Without wraparound you would see four isolated pairs and write a much larger expression.
Checking a group in code
This function derives the term for a list of minterms and rejects groups that are not a legal rectangle. A set of cells is a legal group exactly when its size equals 2 raised to the number of variables that vary inside it.
def term(cells, names="ABCD"):
cells = set(cells)
n = len(names)
bits = [format(c, f"0{n}b") for c in cells]
out = []
for i, name in enumerate(names):
col = {b[i] for b in bits}
if len(col) == 1:
out.append(name if col == {"1"} else name + "'")
if 2 ** (n - len(out)) != len(cells):
raise ValueError("not a rectangle (subcube)")
return "".join(out) or "1"
print(term([0, 2, 8, 10])) # B'D'
print(term([5, 7, 13, 15])) # BD
print(term([2, 3, 6, 7])) # A'C
try:
term([0, 1, 2, 4])
except ValueError as e:
print(e) # not a rectangle (subcube)A procedure that works
Start with the 1s that have the fewest neighbours. They force your choices. Leave the 1s that sit inside many overlapping groups until last.
Worked example 2: overlap and a redundant group
Take F(A,B,C,D) = Σm(0,1,2,3,6,7,14,15).
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 1 | 1 | 1 | 1 |
| 01 | 0 | 0 | 1 | 1 |
| 11 | 0 | 0 | 1 | 1 |
| 10 | 0 | 0 | 0 | 0 |
The largest groups are:
- {0,1,2,3} gives A'B'.
- {2,3,6,7} gives A'C.
- {6,7,14,15} gives BC.
Cells m0 and m1 appear only in A'B', and m14 and m15 appear only in BC, so both of those groups are required. Now check A'C. Its cells 2 and 3 are already covered by A'B', and its cells 6 and 7 are already covered by BC. A'C is therefore redundant, and F = A'B' + BC. This is why step "remove redundant groups" appears in the procedure. A group can be the largest possible and still not be needed. The next chapter names these ideas prime and essential prime implicants.
Common errors
- Groups of 3, 5, or 6. Six adjacent 1s are not a group. Split them into a quad and a pair, or into two overlapping quads. Overlap is allowed and often necessary.
- Diagonal or L-shaped groups. Cells that touch only at a corner are not adjacent. A group must be a rectangle, with wraparound.
- Forgetting wraparound. Check the left and right edges, the top and bottom edges, and the four corners before accepting a result.
- Stopping at small groups. A pair that could have been part of a quad leaves an extra literal in the term. Before you draw a group, ask whether it can grow.
- Including a 0. A group with a single 0 inside is wrong. For SOP, 0s are never grouped.
- Reading complements backwards. In an SOP term, a constant 0 on the label means the letter is complemented.
- Keeping a redundant group. The result is correct as a function but not minimal, and GATE asks for the minimum.
Counting for GATE
After grouping, the number of groups is the number of product terms, and the literal count is the sum of the literals in each term. For example 2, A'B' + BC has 2 terms and 4 literals. A two-level AND-OR implementation needs one AND gate per term with two or more literals, plus one OR gate. Check whether the question counts inverters.
Exercise
Minimize F(A,B,C,D) = Σm(0,1,2,5,8,9,10) using a K-map. Give the SOP expression and its number of literals.
Show answer
Plot the 1s in rows AB=00, 01, 10. Groups: the corner quad {0,2,8,10} gives B'D'. The left-two-columns quad {0,1,8,9} gives B'C'. Cell m5 can only pair with m1, giving the pair {1,5} = A'C'D. Each group is the only choice for some cell (m2 and m10 need B'D', m9 needs B'C', m5 needs A'C'D). So F = B'D' + B'C' + A'C'D, with 3 terms and 2 + 2 + 3 = 7 literals.