3.1.11 · D3Boolean Algebra & Logic Gates

Worked examples — Karnaugh map simplification (2,3,4 variables)

2,517 words11 min readBack to topic

Before anything: a K-map is the truth-table grid where neighbours differ by one variable. A minterm is the row of a truth table whose input bits spell the number in binary. A literal is a single variable, plain () or barred ( = "NOT A"). Our goal each time: cover every 1 with the fewest, largest power-of-two rectangles, then read off the surviving Sum-of-Products expression.


The scenario matrix

Every K-map problem falls into one of these case classes. The examples below are labelled with the cell(s) they cover.

Cell Case class Why it's tricky Covered by
C1 2-variable, ordinary group smallest map, build the reflex Ex 1
C2 3-variable, two groups + overlap when one group isn't enough Ex 2
C3 4-variable, a quad (2×2 block) reading 2 surviving literals Ex 3
C4 Wrap-around edges (torus) the four-corner group Ex 4
C5 Degenerate: all 1s answer is , no literals Ex 5
C6 Degenerate: all 0s / single 1 answer is , or a full minterm Ex 5
C7 Don't-cares enlarging a group treat as 1 only if useful Ex 6
C8 Real-world word problem translate English → minterms Ex 7
C9 Exam twist: 0-grouping for POS grouping 0s gives Product-of-Sums Ex 8

Example 1 — 2-variable, ordinary group (C1)

Forecast: Two 1s sitting together — guess how many literals survive before reading on.

The map. Rows = , columns = (single-bit labels, so Gray code is trivially satisfied).

0 1
0 0 0
1 1 1
  1. Place the 1s. 10 (so ), 11 (so ). Why this step? Decimals must become bit-patterns to know which cells light up.
  2. Grab the largest group. Both 1s fill the entire row → a horizontal pair (group of ). Why this step? Bigger group ⇒ more variables cancelled; two is the max here.
  3. Read surviving literals. Across the pair is 0 then 1 → varies, drop it. in both → stays. Literals . Why this step? The combining theorem deletes the variable that changes.

Recall Verify:

. And are exactly the rows with . ✓


Example 2 — 3-variable, two overlapping groups (C2)

Forecast: Five 1s — five isn't a power of two, so you'll need more than one group. Guess how many.

00 01 11 10
0 1 1 1 1
1 0 0 0 1
  1. Place the 1s. have → the whole top row. 110 () → bottom-right cell. Why? Convert each decimal to to know its cell.
  2. First group — the top row (quad of 4). All four top cells → group of . vary, stays → term . Why this step? Always take the largest legal group first; wait, literal.
  3. Second group — cover the lonely . It has no vertical partner ( above it is already covered, but overlap is allowed!). Pair (110) with (010) — they sit in the same column 10. This vertical pair: varies, , → term . Why this step? Overlapping into the already-covered lets join a size-2 group instead of standing alone as a 3-literal minterm.

Recall Verify:

covers . covers rows with : (010) and (110). Union . ✓ No 1 missed, no extra minterm added.


Example 3 — 4-variable quad, reading two literals (C3)

Forecast: These four cluster into a neat square. Guess the two surviving literals.

Figure — Karnaugh map simplification (2,3,4 variables)
00 01 11 10
00 0 0 0 0
01 0 1 1 0
11 0 1 1 0
10 0 0 0 0
  1. Place the 1s. 0101, 0111, 1101, 1111. They occupy rows and columns . Why? Bit-patterns pin each cell — see the red block in the figure.
  2. Grab the quad. Four cells, power of two, rectangular → legal group of . Why this step? literals — bigger than any pair we could take.
  3. Read the constants. Across the block: is then → drop. is then → drop. everywhere → stays. everywhere → stays. Why this step? Only variables constant across the whole group survive.

Recall Verify:

means : minterms exactly (0101,0111,1101,1111). ✓


Example 4 — wrap-around four corners (C4)

Forecast: These sit in the four corners of the map. On flat paper they look scattered — on a donut they touch. Guess the group.

Figure — Karnaugh map simplification (2,3,4 variables)
00 01 11 10
00 1 0 0 1
01 0 0 0 0
11 0 0 0 0
10 1 0 0 1
  1. Place the 1s. 0000, 0010, 1000, 1010 — the four corner cells. Why? Corners are (left & right edges) crossed with (top & bottom edges).
  2. Wrap the edges. Left edge touches right edge ; top row touches bottom row . All four corners become one group of 4 on the torus (green loops in the figure). Why this step? The map is a donut — opposite edges are adjacent, so this is a legal quad, not four singletons.
  3. Read constants. : vary → drop. : vary → drop. in all four → stays as . in all four → stays as . Why? literals, the two constants.

Recall Verify:

: -0-0 → minterms (0000,0010,1000,1010). ✓


Example 5 — degenerate maps: all-1s and single-1 (C5, C6)

Forecast: What's the simplest possible answer, and the least simplifiable? Guess before reading.

Part (a) — all 1s.

  1. One group of 16. Every cell is 1 → the whole map is a single legal group of . Why? literals — nothing survives.
  2. Read. Every variable takes both values inside the group → all four dropped.

Part (b) — single 1.

  1. No partner exists. has no adjacent 1, so the largest group is size . Why? Grouping needs a neighbouring 1; there is none.
  2. Read the full minterm. 1001. Nothing cancels; literals.

(If instead the map were all 0s, no 1 exists to cover, so — the empty function.)

Recall Verify:

(a) -style collapse of the whole table gives constant . (b) 1001 is decimal , and selects exactly that one row. ✓


Example 6 — don't-cares that pay off (C7)

Forecast: Three cells are offered. Which do you accept? Guess.

00 01 11 10
00 d 1 1 0
01 0 0 0 0
11 0 0 d 0
10 d 1 1 0
  1. Place required 1s and don't-cares. 0001,0011,1001,1011. Don't-cares 0000,1000,1111. Why? We must cover the 1s; the are optional 1s.
  2. Build the biggest group using and . Columns and in rows give cells . Treating as 1 makes a quad. Constants: , ? varies (0,1) → drop; stays. So this quad = . It covers required . Why this step? Accepting the two free turns lonely 1s into a size-4 group ( literals).
  3. Cover remaining . Cells (columns , rows ) form a quad: , , & vary → . Why? Another size-4 group grabs (and re-covers — overlap is free).
  4. Ignore . It never enlarged a needed group, so we treat it as 0. Why? Never invent a term just to cover a don't-care.

Recall Verify:

() = . () = . Union of the required part = ✓ (all required covered), and never forces . ✓


Example 7 — real-world word problem (C8)

Forecast: Guess the final expression before formalising.

  1. Assign variables & minterms. Order bits . Siren when or ( and ). Why? Translate the English conditions into a truth table.
dec
0 0 0 0 0
0 0 1 1 1
0 1 0 2 0
0 1 1 3 1
1 0 0 4 0
1 0 1 5 1
1 1 0 6 1
1 1 1 7 1

So .

00 01 11 10
0 0 1 1 0
1 0 1 1 1
  1. Group the column-pair. Columns and (all four rows) → quad. vary, stays → term . Why? Largest group; captures "motion always fires."
  2. Group the remaining . 110 pairs with 111 (column pair , row ): varies, , → term . Why? Overlap into lets join a size-2 group, matching "both door and window."

Recall Verify:

covers ; covers . Union ✓ — exactly the siren rows, and it reads as English: "motion, or door-and-window." ✓


Example 8 — exam twist: group the 0s for POS (C9)

Forecast: Twelve 1s is a mess to group. There are only four 0s. Guess the POS.

The 0s are at (1001,1011,1101,1111) — i.e. .

00 01 11 10
00 1 1 1 1
01 1 1 1 1
11 1 0 0 1
10 1 0 0 1
  1. Group the 0s instead of the 1s. The four 0s form a quad (rows , cols ). Why this step? Fewer 0s than 1s → grouping them is faster; this is the SOP↔POS duality.
  2. Read the 0-group as a product (this is ). Constants: , (B, C vary). So . Why? Grouping 0s gives the SOP of the complement .
  3. Complement to get POS of . By DeMorgan: . Why? turns the product-of-complement into a sum — a single POS clause.

Recall Verify:

only when , i.e. and → minterms . Those are exactly the missing minterms, so all 12 listed are 1. ✓


Active Recall

Recall When five 1s appear, why can't one group cover them?

is not a power of two; you must use two (or more) overlapping power-of-two groups (Ex 2).

Recall A single isolated 1 in a 4-var map gives how many literals?

— the full minterm survives (Ex 5b).

Recall Why group the 0s in Example 8?

There were only four 0s vs twelve 1s; grouping the smaller set gives , then DeMorgan yields the minimal POS.


Connections