# Karnaugh Maps

A Karnaugh map is an array containing 2k cells where k is the number of variables in the DNF expression to be minimized.  Each cell of the Karnaugh map corresponds to one row of the truth table, or one assignment of truth values to the variables of the expression.  The cells of a Karnaugh map are arranged so that conjunctions which differ on only one variable are adjacent to each other.

## 2-Variable Karnaugh Maps

A 2-variable Karnaugh map has four cells.  The map looks like this: The cells on the top row represent the conjunctions (x and y) and (not x and y).  The cells on the bottom row represent (x and not y) and (not x and not y).

When given a DNF to be minimized, put a 1 in each cell of the Karnaugh map for which there is a conjunction in the DNF.  Then group the cells into groups which contain a power of two cells; that is, make groups of size 2 or 4.  When we get to larger Karnaugh maps you will be able to make groups of size 8 or 16.  Members of groups must to adjacent to one another either horizontally or vertically, and groups must be rectangular in shape.  L-shaped groups are not allowed.

Let's use a Karnaugh map to minimize the following DNF:
_   _     _ _
x y + x y + x y

Here is the Karnaugh map with the appropriate 1's placed in cells and then grouped: The only group that we can make that has the upper right cell in it is the pair in the second column.  And the only group that contains the lower left cell is the pair in the second row.  Note that we can use the lower right cell in both groups.

Once you have grouped cells, you can determine the minimized logical expression.  Each group reduces to one conjunction in the minimized expression.  A group reduces to a conjunction containing just those literals that remain the same for every cell in the group.  For example, the group in the above Karnaugh map that contains the two cells in the second column reduces to the expression "not x" because both of its members have a "not x" in their DNF conjunctions.  The group consisting of both cells in the bottom row reduces to "not y".  Thus the minimized logical expression is
_   _
x + y

## 3-Variable Karnaugh maps

Here is a 3-variable Karnaugh map: In this map, the largest possible group size is 8.  A group of size 8, of course, reduces to true.  We can also make groups of size 4 or 2.  It is important to understand that the leftmost column in this Karnaugh map is considered to be adjacent to the rightmost column.  Thus we can create groups like this one of size 4: That group reduces to the expression y.

When grouping 1's, the object is to get every 1 into as large a group as possible.  Sometimes it is not possible to put a cell into a group; in that case, the minimized expression will contain one conjunction for that cell all by itself.  As before, if it helps make larger groups we can put a cell in more than one group.

Use a Karnaugh map to minimize the following DNF:
_     _ _         _   _ _ _   _   _
x y z + x y z + x y z + x y z + x y z + x y z

Here is the Karnaugh map: The reduced expression is
_   _ _
x z + y + x z

The worst case situation when attempting to minimize a DNF is to end up with a Karnaugh map that looks like a checkerboard.  In such a case, no minimization is possible.

## 4-Variable Karnaugh Maps

A 4-variable Karnaugh map looks like this: In a map of this size, we can have groups of size 16, 8, 4, or 2. You must realize that the leftmost column is considered to be adjacent to the rightmost column and that the top row is adjacent to the bottom row.  Here are some 4-variable Karnaugh maps and the resulting minimized expressions: 