About

6.2 Decision Tables

Theory: Decision Tables

Equivalence partitioning handles inputs one at a time. But many requirements are about combinations of inputs: if this and that, then do something. For those, the course’s next black box tool is the decision table.

What It Is, and When to Use It

Think of a shop’s delivery policy: if the customer has a member card and the order is over 500 baht, then delivery is free; otherwise delivery is charged. Requirements like this are if-then rules, and they are everywhere. A decision table writes such rules in a neat table, so that nothing is forgotten.

The Parts of a Decision Table

PartWhereMeaning
Conditions C1…CkC_1 \ldots C_ktop rowsthe inputs
Actions A1…AmA_1 \ldots A_mbottom rowsthe outputs
Rules R1,R2,…R_1, R_2, \ldotscolumnsone column = one rule: if these conditions, then these actions
Entriescells1 = true, 0 = false, X = don’t care

Here is the delivery policy as a decision table:

R1R2R3
C1: has a member card110
C2: order over 500 baht10X
A1: free delivery100
A2: charge delivery011

Read each column top to bottom as one sentence. R1: if member and over 500, then free delivery. R3: if not a member, then charge delivery, whatever the order total (that is what the X says).

It Is a Truth Table, Turned Sideways

The professor asked the class: does this look familiar? It should. A decision table is a truth table, transposed: the rows became columns. So the same problem appears as with brute force:

With KK conditions, a full decision table has 2K2^K rules.

Making It Smaller: “Don’t Care”

Often a condition does not matter for a rule. Then we write X (don’t care). One column with an X replaces two columns, one with 1 and one with 0, so several rules merge into one and the table becomes much smaller. In the delivery table, R3 (C1 = 0, C2 = X) stands for two full rules, (0, 1) and (0, 0), which both charge delivery: the full table has 22=42^2 = 4 rules, the reduced one 3.

You can also use a K-map (from digital logic) to find the don’t cares systematically: neighbouring cells with the same action merge, exactly as rules merge.

Common mistake: using X just to make the table shorter. Mark a condition X only when changing it cannot change the rule’s action. If it can, you have merged two rules that behave differently, and the table no longer says what the specification says.

Five Properties to Remember

  1. The order of the conditions does not change the meaning of a rule.
  2. The order of the rules does not change the result.
  3. Once a rule matches and an action is chosen, no other rule needs to be checked.
  4. If one rule gives several actions, their order is not important.
  5. Rules are complete (every combination of inputs is covered by some rule) and consistent (the same inputs always give the same action).

Exam-style answer: A requirement has 5 conditions. How many rules does a full decision table have? How can you reduce them?

25=322^5 = 32 rules. Reduce them with don’t care (X) entries: when a condition does not affect a rule, write X and merge the columns. Build a cause-effect graph first (6.3), so you keep only the input combinations that matter.


Worked Examples

Exercise 1

How is a decision table related to a truth table?

Show solution ↓
Solution

A decision table is a truth table turned sideways (transposed): each row of the truth table becomes a column, a rule. So a full decision table with KK conditions has the same number of rules as the truth table has rows, 2K2^K.

Exercise 2

A requirement has 5 conditions. How many rules does a full decision table have? How can you reduce them?

Show solution ↓
Solution

Each condition is true or false, so

25=32 rules.2^5 = 32 \text{ rules.}

32 rules. To reduce them, use don’t care (X) entries: wherever a condition cannot affect a rule’s action, write X and merge the two columns into one. Better still, draw a cause-effect graph first, so the table is built only from the input combinations that matter.

Exercise 3

A text editor has 4 Boolean conditions (copy, paste, bold, underline). How many rules does the full table have? How many with 10 conditions? What does this tell you?

Show solution ↓
Solution
  • 4 conditions: 24=2^4 = 16 rules.
  • 10 conditions: 210=2^{10} = 1,024 rules.

Each extra condition doubles the table. Like brute force, the full table explodes, which is why we reduce it with don’t cares and cause-effect graphs.

Exercise 4

A cinema’s rule: a student with a valid student card gets a discount; anyone without a valid card pays full price, whether or not they are a student. Write the full decision table with conditions C1 (is a student) and C2 (has a valid card), then reduce it with X.

Show solution ↓
Solution

Full table (22=42^2 = 4 rules). Only a student who also has a valid card gets the discount:

R1R2R3R4
C1: is a student1100
C2: valid card1010
A1: discount1000
A2: full price0111

Reduce. R2 and R4 both have C2 = 0 and the same action (full price); C1 does not matter there, so they merge into one rule with C1 = X. R3 (C1 = 0, C2 = 1) stays as it is: it differs from R2 in both conditions, so those two cannot merge.

R1R2’R3
C1: is a student1X0
C2: valid card101
A1: discount100
A2: full price011

3 rules. Check completeness: (1,1) → R1, (1,0) and (0,0) → R2’, (0,1) → R3 ✓; every input matches exactly one rule.

(Merging R3 and R4 instead, as C1 = 0, C2 = X, and keeping R2 also gives 3 rules. Either reduction is correct, as long as every X is truly a don’t care.)

Exercise 5

Check this table against the five properties. Which properties does it break, and how would you show it with a test?

R1R2
C11X
C2X1
A110
A201
Show solution ↓
Solution

Go through all 22=42^2 = 4 input combinations:

(C1, C2)Matching rulesActions
(1, 0)R1A1
(0, 1)R2A2
(1, 1)R1 and R2A1 and A2 conflict
(0, 0)noneno action
  • It is not consistent: input (1, 1) matches both rules, which give different actions.
  • It is not complete: input (0, 0) matches no rule.

Tests that expose it: (1, 1), where the expected action is undefined, and (0, 0), where nothing is specified. A tester reports both as specification problems and asks what should happen.