IGCSE · Practice questions · Dry-running algorithms with trace tables

One line at a time.

Six original Cambridge-style trace table questions, each checked by dry-running the code.

Original questions All questions on this page are original work, written in the Cambridge IGCSE style. They are not from past papers. They test the same concepts and skills the syllabus rewards.
Keep these straight

Follow the code, not your guess.

01
Trace
[4 marks]

Complete a trace table for this algorithm.

A ← 1
B ← 1
FOR I ← 1 TO 4
    C ← A + B
    A ← B
    B ← C
    OUTPUT C
NEXT I
  • I = 1: C = 2, A = 1, B = 2, output 2. ✓
  • I = 2: C = 3, A = 2, B = 3, output 3. ✓
  • I = 3: C = 5, A = 3, B = 5, output 5. ✓
  • I = 4: C = 8, A = 5, B = 8, output 8. ✓
02
Trace
[3 marks]

Dry-run the digit-sum algorithm from this lesson with the input 608. Give the values of Digit, Sum and Number after each pass, and the output.

  • Pass 1: Digit 8, Sum 8, Number 60. ✓
  • Pass 2: Digit 0, Sum 8, Number 6; Pass 3: Digit 6, Sum 14, Number 0. ✓
  • Output 14. ✓
03
Trace
[4 marks]

Complete a trace table for this algorithm with the inputs 15, 40, 25, 0.

Max ← 0
Total ← 0
INPUT Value
WHILE Value <> 0 DO
    Total ← Total + Value
    IF Value > Max
      THEN
        Max ← Value
    ENDIF
    INPUT Value
ENDWHILE
OUTPUT Total, " ", Max
  • Value 15: Total 15, Max 15. ✓
  • Value 40: Total 55, Max 40. ✓
  • Value 25: Total 80 (Max stays 40). ✓
  • Value 0 ends the loop; output 80 40. ✓
04
Calculate
[2 marks]

State the values of DIV(29, 4) and MOD(29, 4).

  • DIV(29, 4) = 7. ✓
  • MOD(29, 4) = 1. ✓
05
Trace
[3 marks]

Dry-run this algorithm and state each output.

Count ← 10
REPEAT
    IF Count > 5
      THEN
        Count ← Count - 3
      ELSE
        Count ← Count - 1
    ENDIF
    OUTPUT Count
UNTIL Count <= 2
  • 10 > 5: Count 7, output 7. 7 > 5: Count 4, output 4. ✓
  • 4 is not > 5: Count 3, output 3. ✓
  • 3 is not > 5: Count 2, output 2; 2 <= 2 so the loop stops. Outputs: 7, 4, 3, 2. ✓
06
Explain
[2 marks]

Explain why a trace table is useful when testing an algorithm.

  • It shows the value of each variable (and each output) at every step of the algorithm. ✓
  • So the actual results can be compared with the expected results, and the line where an error happens can be found. ✓

Mark this once you have attempted all six and checked your working. It records a Practiced badge on the topic and adds a one-time bonus. Revealing the solutions alone does not count.