COS 102 · Problem Solving
Our notes
2 min readWhy we need them
When an action depends on several conditions at once, nested IFs become hard to check. A decision table or decision tree lists every combination so none is forgotten.
Decision table: parts
| Part | Holds |
|---|---|
| Condition stub | the conditions (questions) |
| Condition entries | Y/N for each rule (column) |
| Action stub | the possible actions |
| Action entries | X where an action applies under that rule |
With n yes/no conditions there are 2ⁿ rules: 2 conditions give 4, 3 give 8.
Worked example: hostel allocation
Conditions: C1 final-year student? C2 paid fees? Actions: A1 allocate a room; A2 put on the waiting list; A3 refuse until fees are paid.
| R1 | R2 | R3 | R4 | |
|---|---|---|---|---|
| C1 Final year | Y | Y | N | N |
| C2 Fees paid | Y | N | Y | N |
| A1 Allocate | X | |||
| A2 Waiting list | X | |||
| A3 Refuse | X | X |
R2 and R4 have the same action whatever C1 is, so they can be merged into one rule "C2 = N → refuse" (C1 marked "–", don't care). The table shrinks to 3 rules.
Decision trees
A decision tree shows the same logic as branches: start at the root with the first condition, branch Yes/No, then the next condition, and end in leaves that hold the actions.
Fees paid?
- No → Refuse
- Yes → Final year?
- Yes → Allocate
- No → Waiting list
Trees are easier to read; tables are better for checking that every combination is covered.
Worked example: counting rules
A shop gives a discount based on three conditions: student ID shown, purchase over ₦10,000, paying by transfer. Full table: 2³ = 8 rules. If the discount needs ID and over ₦10,000 whatever the payment method, the rules (Y, Y, Y) and (Y, Y, N) merge into one.
From table to code
Each rule becomes one branch of an IF chain, or the table itself can be stored as data the program looks up, which makes later changes easy.
Exams usually ask
- Draw a decision table (and simplify it) for a given policy.
- Convert a decision table into a decision tree or pseudocode.
Common mistake
Leaving out combinations. Always check that the number of rules is 2ⁿ before merging.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Decision table
(opens en.wikipedia.org in a new tab)
Wikipedia, Decision table, CC BY-SA 4.0 · licence
-
Decision tree
(opens en.wikipedia.org in a new tab)
Wikipedia, Decision tree, CC BY-SA 4.0 · licence
Watch
-
Best pick What is Decision Table Testing? Software Testing Tutorial
2 min · ≈ 9 MB · about ₦5
(opens youtube.com in a new tab)
-
Decision Analysis 3: Decision Trees
3 min · ≈ 14 MB · about ₦8
(opens youtube.com in a new tab)
-
Software Testing Tutorial #36 - Decision Table Testing in Software Testing
12 min · ≈ 54 MB · about ₦30
(opens youtube.com in a new tab)
-
Simplifying Decision Tables
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
Decision Table solved example - Software Engineering
15 min · ≈ 68 MB · about ₦38
(opens youtube.com in a new tab)
We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.