Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
OCR GCSE Computer Science (Paper 2) Smart practice A mixed round aimed at your weak spots
Unit 1
Algorithms
Unit 2
Programming fundamentals
Unit 3
Producing robust programs
Unit 4
Boolean logic
Unit 5
Programming languages and IDEs
Unit 6
Practical programming (Section B)
Avg
score:
–
Topics
done:
0/31

Trace tables

Practise 28 exam-style questions on Trace tables for OCR GCSE 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 the Study Helper on hand if you get stuck.

  • 28 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

2 marks

Here is part of a program.

function calc(a, b)
    result = a * 2 + b
    return result
endfunction

x = calc(3, 4)
y = calc(x, 1)
print(y)

State the value of x and the output of the program.

Model answer

x = 10
Output: 21

Explanation

calc(3, 4) works out 3 * 2 + 4 = 10 and returns it, so x = 10. The second call passes x as a, so it works out 10 * 2 + 1 = 21, which is stored in y and output. Multiplication is done before addition, so 3 * 2 + 4 is 10, not 14.

Mark scheme
  1. 1 mark

    x = 10

  2. 1 mark

    21

    follow through: 2 × the student's x + 1

Question 2

3 marks

Here is an algorithm.

name = "Jasmine"
a = name.left(3)
b = name.substring(4, 2)
c = b + a
print(c.upper)

State the value of a, the value of b and the output of the algorithm.

Model answer

a = Jas
b = in
Output: INJAS

Explanation

left(3) takes the first three characters, Jas. substring(4, 2) starts at index 4 - counting J as 0, that is the i - and takes 2 characters, giving in. c joins b then a, giving inJas, and .upper converts it to INJAS. Remember that indexing starts at 0, and that the second number in substring is how many characters to take, not an end position.

Mark scheme
  1. 1 mark

    a = Jas

    accept "Jas"; the case must be correct (a capital J, then lower-case a and s)

  2. 1 mark

    b = in

    accept "in"

  3. 1 mark

    INJAS

    must be in capital letters; follow through: the student's b followed by their a, in capitals

Question 3

4 marks

Here is an algorithm.

total = 0
for i = 1 to 4
    total = total + i * 2
next i
print(total)

The trace table shows a dry run of the algorithm. P, Q, R and S stand for missing values.

State the values of P, Q, R and S.

Trace table with three columns: i, total and Output. Row 1: total = 0; i and Output blank. Row 2: i = 1, total = 2; Output blank. Row 3: i = 2, total is the letter P; Output blank. Row 4: i = 3, total is the letter Q; Output blank. Row 5: i = 4, total is the letter R; Output blank. Row 6: Output is the letter S; i and total blank.

Model answer

P = 6
Q = 12
R = 20
S = 20

Explanation

Multiplication is done before addition, so each pass adds i * 2: 2, 4, 6 and then 8. The running total goes 2, 6, 12, 20. The print comes after next i, so 20 is output once, at the end. A common mistake is to work out (total + i) * 2.

Mark scheme
  1. 1 mark

    P = 6

  2. 1 mark

    Q = 12

    follow through: the student's P + 6

  3. 1 mark

    R = 20

    follow through: the student's Q + 8

  4. 1 mark

    S = 20

    follow through: equal to the student's R

Question 4

5 marks

Here is an algorithm.

array nums = [3, 8, 1, 6, 4]
for i = 0 to 1
    temp = nums[i]
    nums[i] = nums[4 - i]
    nums[4 - i] = temp
next i

The first row of the trace table shows the contents of the array before the loop starts.

Write the values of i and temp, and any changes to the array, for each pass of the loop. Then state the purpose of the algorithm.

Trace table with seven columns: i, temp, nums[0], nums[1], nums[2], nums[3] and nums[4]. Columns nums[0] to nums[4] are grouped under the heading nums. Row 1: nums[0] = 3, nums[1] = 8, nums[2] = 1, nums[3] = 6, nums[4] = 4; i and temp blank. Rows 2 to 4 are empty, for the student to complete.

Model answer

Pass i = 0: temp = 3, nums[0] = 4, nums[4] = 3
Pass i = 1: temp = 8, nums[1] = 6, nums[3] = 8
The array ends as 4, 6, 1, 8, 3. The algorithm reverses the order of the values in the array.

Explanation

Each pass swaps one pair of elements from opposite ends, using temp to keep the first value safe. When i = 0, nums[0] and nums[4] swap (3 and 4); when i = 1, nums[1] and nums[3] swap (8 and 6). The middle element, nums[2], stays where it is, so the array ends as 4, 6, 1, 8, 3: the original order reversed.

Mark scheme
  1. 1 mark

    pass i = 0: temp = 3

    The values may be set out as a table or as rows. Accept the whole array written out after each pass (4, 8, 1, 6, 3 then 4, 6, 1, 8, 3).

  2. 1 mark

    pass i = 0: nums[0] = 4 and nums[4] = 3

  3. 1 mark

    pass i = 1: temp = 8

  4. 1 mark

    pass i = 1: nums[1] = 6 and nums[3] = 8

    nums[2] never changes

  5. 1 mark

    purpose: reverses (the order of the values in) the array

    accept 'swaps the first and last values, then the second and fourth'; do not accept 'sorts the array'

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

Study Helper Hints first, answers after you try

Stuck on this one? Ask for a hint and I’ll point you in the right direction, without giving the answer away. Once you’ve checked your answer, I’ll show you how the marks are awarded.