# Truth Tables for 2-Input & 3-Input Circuits

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 10: Boolean Logic & Gate Circuits
- **Estimated Duration:** 15 minutes
- **Access:** Open Theory (All-Access for Interactive IDE &amp; Autotests)

---

## Theory & Conceptual Background

A Truth Table is a comprehensive mathematical table that displays the output state of a digital logic circuit for every possible combination of binary inputs.

1. Determining the Size of a Truth Table
For any digital circuit with $n$ distinct binary inputs, the number of unique input combinations is given by the formula:
$$\text{Number of Rows} = 2^n$$
1 Input ($A$): $2^1 = 2$ rows (0, 1).2 Inputs ($A, B$): $2^2 = 4$ rows (00, 01, 10, 11).3 Inputs ($A, B, C$): $2^3 = 8$ rows (000 through 111).4 Inputs ($A, B, C, D$): $2^4 = 16$ rows.

2. Standard Binary Ordering for 3-Input Tables
In Cambridge examinations, truth table rows must always follow standard ascending binary sequence:
Row 1:  0 0 0  (Binary 0)
Row 2:  0 0 1  (Binary 1)
Row 3:  0 1 0  (Binary 2)
Row 4:  0 1 1  (Binary 3)
Row 5:  1 0 0  (Binary 4)
Row 6:  1 0 1  (Binary 5)
Row 7:  1 1 0  (Binary 6)
Row 8:  1 1 1  (Binary 7)
The Alternation Pattern Trick:
To write an 8-row table quickly without skipping combinations:
Rightmost input ($C$): alternates every row: 0, 1, 0, 1, 0, 1, 0, 1.Middle input ($B$): alternates in pairs: 0, 0, 1, 1, 0, 0, 1, 1.Leftmost input ($A$): alternates in blocks of four: 0, 0, 0, 0, 1, 1, 1, 1.

3. Using Intermediate Columns for Complex Circuits
When tracing a multi-gate circuit such as:
$$X = (A \text{ AND } B) \text{ OR } (\text{NOT } C)$$
Candidates should always construct intermediate columns for each sub-expression before computing the final output $X$:

  
    $A$$B$$C$$P = A \text{ AND } B$$Q = \text{NOT } C$$X = P \text{ OR } Q$
    000011001000010011011000100011101000110111111101
  

4. Methodical Evaluation Strategy
Calculate column $P$ ($A \text{ AND } B$):
Only rows where both $A=1$ and $B=1$ produce $1$ (Rows 7 and 8). All other rows are $0$.
Calculate column $Q$ ($\text{NOT } C$):
Flip each value in column $C$ ($0 \rightarrow 1$, $1 \rightarrow 0$).
Calculate final output $X$ ($P \text{ OR } Q$):
Check columns $P$ and $Q$. If either column contains a $1$, write $1$; only write $0$ if both are $0$.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Sizing Truth Tables for n-Input Circuits (Multiple choice, 25 XP)

**Instructions:**
A logic circuit has 3 binary inputs named $A$, $B$, and $C$. How many total rows of input combinations must be included in a complete truth table for this circuit?

**Options:**
- **A**: 6 rows, calculated as 3 inputs multiplied by 2 states (3 * 2 = 6).
- **B**: 8 rows, calculated as 2^3 because each of the 3 independent inputs can be either 0 or 1.
- **C**: 4 rows, because each input has two states.
- **D**: 9 rows, calculated as 3 squared (3^2 = 9).


**Autotest Expectations:**
- **Correct truth table row count identified**: `selection_match` -> Expected: `opt_eight_rows`

### Exercise 2: Exam-Style Question: Truth Table Column Tracing (Fill in blank, 35 XP)

**Instructions:**
Given binary input values $A = 1$, $B = 0$, and $C = 1$: Evaluate the intermediate and final binary outputs (0 or 1):

1. $P = A \text{ AND } B \rightarrow$ [blank_1]
2. $Q = \text{NOT } C \rightarrow$ [blank_2]
3. $R = A \text{ OR } B \rightarrow$ [blank_3]
4. $X = P \text{ OR } Q \rightarrow$ [blank_4]


**Starter Code:**
```text
{"prompt":"Given binary input values $A = 1$, $B = 0$, and $C = 1$:\nEvaluate the intermediate and final binary outputs (0 or 1):","template":"1. $P = A \\text{ AND } B \\rightarrow$ [blank_1]\n2. $Q = \\text{NOT } C \\rightarrow$ [blank_2]\n3. $R = A \\text{ OR } B \\rightarrow$ [blank_3]\n4. $X = P \\text{ OR } Q \\rightarrow$ [blank_4]","word_bank":["0","1"]}
```

**Autotest Expectations:**
- **Value of P (1 AND 0)**: `text_exact` -> Expected: `0`
- **Value of Q (NOT 1)**: `text_exact` -> Expected: `0`
- **Value of R (1 OR 0)**: `text_exact` -> Expected: `1`
- **Value of X (0 OR 0)**: `text_exact` -> Expected: `0`

### Exercise 3: Exam-Style Question: Truth Table: 3-Input Logic Circuit (Logic gate, 50 XP)

**Instructions:**
Complete the 8-row truth table for circuit output $X = (A \text{ AND } B) \text{ OR } (\text{NOT } C)$:


**Starter Code:**
```text
{"mode": "truth_table", "expression": "(A AND B) OR (NOT C)", "columns": ["A", "B", "C", "A AND B", "NOT C", "X"], "rows": [{"inputs": {"A": 0, "B": 0, "C": 0}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 0, "B": 0, "C": 1}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 0, "B": 1, "C": 0}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 0, "B": 1, "C": 1}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 1, "B": 0, "C": 0}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 1, "B": 0, "C": 1}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 1, "B": 1, "C": 0}, "blanks": ["A AND B", "NOT C", "X"]}, {"inputs": {"A": 1, "B": 1, "C": 1}, "blanks": ["A AND B", "NOT C", "X"]}]}
```

**Autotest Expectations:**
- **Complete truth table matches expected values**: `truth_table_match` -> Expected: ``

