UNIHIVE

Study Hub UNIPORT COS 102

COS 102 · Problem Solving

Decision tables and decision trees

Laying out complex conditions and their actions so no case is missed.

Our notes

2 min read

Why 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

PartHolds
Condition stubthe conditions (questions)
Condition entriesY/N for each rule (column)
Action stubthe possible actions
Action entriesX 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.

R1R2R3R4
C1 Final yearYYNN
C2 Fees paidYNYN
A1 AllocateX
A2 Waiting listX
A3 RefuseXX

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

Watch

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.

All COS 102 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.