Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Subject:
Topics:
Avg
score:
–
Topics
done:
0/32

Trace tables

Practise 37 exam-style questions on Trace tables for Cambridge IGCSE Computer Science (Paper 2). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with an AI tutor on hand if you get stuck.

  • 37 questions
  • 1–6 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

1 mark

Look at this algorithm:

X ← 29
Y ← 4
X ← MOD(X, Y) + DIV(X, Y)
OUTPUT X

State the output from this algorithm.

Model answer

8

Explanation

29 divided by 4 is 7 remainder 1, so DIV(29, 4) is 7 and MOD(29, 4) is 1. The new value of X is 1 + 7 = 8.

Mark scheme
  1. 1 mark

    8

Question 2

2 marks

The array Prices holds 2.50, 3.75, 1.20 and 4.10 in Prices[1] to Prices[4].

Total ← 0
FOR Index ← 1 TO 4
    Total ← Total + Prices[Index]
NEXT Index
Average ← ROUND(Total / 4, 2)
OUTPUT "Average price: ", Average

Give the values that Total takes during a dry run, and the output.

Model answer

Total: 0, 2.5, 6.25, 7.45, 11.55
Output: Average price: 2.89

Explanation

Total adds one price on each pass of the loop. After the loop, 11.55 ÷ 4 = 2.8875, and ROUND(..., 2) gives 2 decimal places, so 2.89 is output. A common slip is to truncate to 2.88 instead of rounding.

Mark scheme
  1. 1 mark

    Total: 0, 2.5, 6.25, 7.45, 11.55

    Accept 2.50 and 0.0 etc.

  2. 1 mark

    Output: Average price: 2.89

    Do not accept 2.8875 or 2.88.

Question 3

3 marks

The trace table shown has been started for this algorithm, with the input Cat42x.

OUTPUT "Enter a password"
INPUT Password
Digits ← 0
FOR Index ← 1 TO LENGTH(Password)
    Character ← SUBSTRING(Password, Index, 1)
    IF Character >= "0" AND Character <= "9"
      THEN
        Digits ← Digits + 1
    ENDIF
NEXT Index
IF Digits >= 2
  THEN
    OUTPUT "Strong"
  ELSE
    OUTPUT "Weak"
ENDIF

Give the values that would be written in the rest of the Index, Character, Digits and OUTPUT columns.

Trace table with five columns: Password, Index, Character, Digits and OUTPUT. Row 1: Password = Cat42x, OUTPUT = "Enter a password"; Index, Character and Digits blank. Row 2: Digits = 0; Password, Index, Character and OUTPUT blank. Rows 3 to 10 are empty, for the student to complete.

Model answer

Index: 1, 2, 3, 4, 5, 6
Character: C, a, t, 4, 2, x
Digits: 1, 2
OUTPUT: Strong

Explanation

The loop runs once for each of the 6 characters, and SUBSTRING takes one character at a time. Only the characters 4 and 2 are between "0" and "9", so Digits goes up twice. After the loop, Digits >= 2 is TRUE, so Strong is output.

Mark scheme
  1. 1 mark

    Index: 1, 2, 3, 4, 5, 6 with Character: C, a, t, 4, 2, x

  2. 1 mark

    Digits: 1, 2 (when Character is 4 and then 2)

  3. 1 mark

    OUTPUT: Strong

Question 4

5 marks

The trace table shown has been started for this algorithm. The inputs are 23, 17, 31, 19 and -1, in that order.

Count ← 0
INPUT Reading
Min ← Reading
Max ← Reading
WHILE Reading <> -1 DO
    Count ← Count + 1
    IF Reading < Min
      THEN
        Min ← Reading
    ENDIF
    IF Reading > Max
      THEN
        Max ← Reading
    ENDIF
    INPUT Reading
ENDWHILE
OUTPUT Count, " ", Min, " ", Max

Give the values that would be written in the rest of each column, in order.

Trace table with five columns: Reading, Count, Min, Max and OUTPUT. Row 1: Reading = 23, Count = 0, Min = 23, Max = 23; OUTPUT blank. Rows 2 to 7 are empty, for the student to complete.

Model answer

Reading: 17, 31, 19, -1
Count: 1, 2, 3, 4
Min: 17
Max: 31
OUTPUT: 4 17 31

Explanation

The first reading sets both Min and Max to 23. Inside the loop each reading is counted and compared, then the next reading is input at the end of the pass. When -1 is input, the WHILE condition is false, so -1 is never counted or treated as the minimum - this is why the rogue value is tested before it is processed.

Mark scheme
  1. 1 mark

    Reading: 17, 31, 19, -1

  2. 1 mark

    Count: 1, 2, 3, 4

    Do not accept 5.

  3. 1 mark

    Min: 17

    Do not accept -1.

  4. 1 mark

    Max: 31

  5. 1 mark

    OUTPUT: 4 17 31

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

AI Tutor Hints first, answers after you try

Hi! Stuck? Ask me for a hint and I’ll help you work it out. Once you’ve checked your answer I can explain exactly where the marks are.