Sub topic 14
The Quine-McCluskey tabular method
This chapter assumes you can convert between binary and decimal. It also assumes you know minterm notation, such as Σm(0,1,2), and have seen Karnaugh map grouping. Karnaugh maps work well up to four variables. The Quine-McCluskey (QM) method does the same job as a table procedure, so it works for any number of variables and is easy to program. It has two stages. The first finds every prime implicant. The second selects a minimal set of them (the chart, covered in the next chapter).
The core idea
Two product terms can be merged when they differ in exactly one variable. This is the identity xA + x'A = A. On a K-map, this is two adjacent cells. In QM, two binary strings are written side by side and compared bit by bit.
001and101differ in one bit, so they merge into-01. The dash means the variable is eliminated.001and110differ in three bits, so they cannot merge.0-1and01-have their dashes in different positions, so they cannot merge, even though they look close.
Only terms with dashes in the same positions can merge. The same variable must be missing from both.
Why group by the number of ones
Two strings that differ in exactly one bit must have ones counts that differ by exactly 1. So you only need to compare a term with terms in the next group up. This cuts the number of comparisons.
The procedure
Worked example
Take F(A,B,C) = Σm(0,1,2,5,6,7).
Pass 0. Write each minterm in binary and group by the number of ones.
| Group | Minterm | A B C |
|---|---|---|
| 0 | 0 | 000 |
| 1 | 1 | 001 |
| 1 | 2 | 010 |
| 2 | 5 | 101 |
| 2 | 6 | 110 |
| 3 | 7 | 111 |
Pass 1. Compare group 0 with group 1, group 1 with group 2, and group 2 with group 3.
| Pair | Result | Terms covered |
|---|---|---|
| 0 and 1 | `00-` | 0, 1 |
| 0 and 2 | `0-0` | 0, 2 |
| 1 and 5 | `-01` | 1, 5 |
| 2 and 6 | `-10` | 2, 6 |
| 5 and 7 | `1-1` | 5, 7 |
| 6 and 7 | `11-` | 6, 7 |
The pairs 1 and 6, 2 and 5, and 1 and 2 are not listed because they differ in more than one bit. Every original minterm was merged at least once, so all of them are marked.
Pass 2. Compare the six new terms. Any two of them have their dashes in different positions, so none can merge. The process stops. No term is left unmarked from pass 0, so the six pass-1 terms are all prime implicants:
A'B', A'C', B'C, BC', AC, AB
The same procedure in Python
This function repeats the combine step until nothing merges. It keeps every term that was never merged.
def combine(a, b):
diff = [i for i, (x, y) in enumerate(zip(a, b)) if x != y]
if len(diff) == 1 and a[diff[0]] != '-' and b[diff[0]] != '-':
i = diff[0]
return a[:i] + '-' + a[i + 1:]
return None
def prime_implicants(minterms, n):
terms = {format(m, f'0{n}b') for m in minterms}
primes = set()
while terms:
used, nxt = set(), set()
for a in terms:
for b in terms:
c = combine(a, b)
if c:
nxt.add(c)
used.update((a, b))
primes |= terms - used
terms = nxt
return sorted(primes)
print(prime_implicants([0, 1, 2, 5, 6, 7], 3))The output is ['-01', '-10', '0-0', '00-', '1-1', '11-'], matching the hand result. Three details of the code match the table method:
combinerejects a pair if either string has a dash at the differing position. This enforces the "same dash positions" rule.nxtis a set, so a duplicate result is stored once.primes |= terms - usedcollects the terms of the current pass that merged with nothing.
The code compares every pair instead of only adjacent groups. This gives the same answer but does more work. Hand work should use the grouping.
Duplicates
A merged term can arise from several different pairs. For example, take minterms 1, 3, 5, 7. Pass 1 gives 0-1, -01, -11 and 1-1. In pass 2, 0-1 with 1-1 gives --1, and -01 with -11 also gives --1. Write --1 once. Listing it twice only wastes effort in the next pass.
Don't-cares
Treat a don't-care as a minterm in the first stage. Include its binary string in the list. This lets it merge into larger terms, which is the reason for having don't-cares.
In the second stage, the chart, don't-cares are not columns. A don't-care never has to be covered. If a prime implicant covers only don't-cares, it is never needed in the cover.
For example, take F = Σm(1,3) + d(7). The list is 1, 3, 7:
- 1 and 3 merge into
0-1. - 3 and 7 merge into
-11. - Pass 2 produces nothing, because the dashes are in different positions.
The prime implicants are A'C and BC. Minterm 1 is covered only by A'C, so it is essential. A'C also covers 3, so BC is not needed.
Common errors
- Merging terms with dashes in different positions.
0-1and01-cannot merge. Always check the dashes first. - Forgetting that a term can be used more than once. Marking a term as used does not remove it from other comparisons. A term can merge with several partners. Marking only means it is not prime.
- Treating a term as prime because it appeared in an earlier pass. A term is prime only if it was never merged in the pass where it was compared. Check by pass, not by the list.
- Including don't-cares as chart columns. They are in the table but not in the chart.
- Comparing non-adjacent groups. Groups 0 and 2 cannot merge. Their strings differ in at least two bits.
- Mixing up bit order. Read the string left to right as the most significant variable (A) to the least. Convert
-01asB'Cwhen the variables are A, B, C.
Where QM stops
For the example function, each minterm is covered by exactly two primes, and no prime is essential. The cover is cyclic. Two minimal covers each use three primes:
A'B' + BC' + ACA'C' + B'C + AB
Both have six literals. Choosing between them requires a systematic method such as Petrick's method, which a later chapter covers.
Cost
The method is exact, and the number of prime implicants can grow exponentially with the number of variables. For GATE, you will mostly run it by hand on three or four variables. The point of the exam question is usually to count prime implicants or identify the essential ones, not to compute the final minimal form.
Exercise
Run Quine-McCluskey on F(A,B,C) = Σm(1,3,5,7). List the terms produced in each pass, and give the prime implicants and the minimal expression.
Show answer
Pass 0: 001, 011, 101, 111. Pass 1: 0-1 (1,3), -01 (1,5), -11 (3,7), 1-1 (5,7). Pass 2: 0-1 with 1-1 gives --1, and -01 with -11 gives --1. Write --1 once. No further merges are possible. All pass-1 terms were merged, so the only prime implicant is --1, which is C. The minimal expression is F = C.
Exercise
For F = Σm(0,1) + d(2,3) over three variables A, B, C, with A as the most significant bit, find all prime implicants. Which are needed to cover the required minterms?
Show answer
List 0, 1, 2, 3 as 000, 001, 010, 011. Pass 1: 00- (0,1), 0-0 (0,2), 0-1 (1,3), 01- (2,3). Pass 2: 00- with 01- gives 0--, and 0-0 with 0-1 gives 0--. Write 0-- once. The only prime implicant is 0--, which is A'. It covers the required minterms 0 and 1, so F = A'. The don't-cares 2 and 3 helped form the larger term, but they need no coverage.