AQA GCSE Computer Science Paper 1 (1C), June 2025: Question 8

6 marks · Medium difficulty · Trace Table

Complete a trace table for an algorithm manipulating binary strings using nested selection and iteration, and explain why zero-based indexing requires the upper bound of the loop to be the length minus 1.

Practise this question

Question

Question 08 presents Figure 8 showing pseudo-code lines 1 to 15. The algorithm initializes b1 as '0010', b2 as '0111', and new as an empty string. A for loop runs with index i from 0 to LEN(b1) - 1. Inside, nested IF statements perform an XOR-like condition using OR, NOT, and AND logic to append '1' or '0' to new. In Question 08.1 (5 marks), students must complete an empty trace table with columns for b1, b2, new, and i across 8 rows. In Question 08.2 (1 mark), students must explain why line 4 uses LEN(b1) - 1 instead of LEN(b1).
Question text

08 Figure 8 shows an algorithm represented using pseudo-code.

• Line numbers are included but are not part of the algorithm.

Figure 8

1 b1 '0010'

2 b2 '0111'

3 new ''

4 FOR i 0 TO LEN(b1) - 1

5 IF b1[i] = '1' OR b2[i] = '1' THEN

6 IF NOT (b1[i] = '1' AND b2[i] = '1') THEN

7 new new + '1'

8 ELSE

9 new new + '0'

10 ENDIF

11 ELSE

12 new new + '0'

13 ENDIF

14 ENDFOR

15 OUTPUT new

08.1 Complete the trace table for the algorithm shown in Figure 8.

You may not need to use all the rows in the table.

[5 marks]

b1 b2 new i

08.2 Explain why line 4 in Figure 8 uses LEN(b1) - 1 instead of LEN(b1)

[1 mark]

Mark scheme

Show the mark scheme Mark scheme for Question 08. Part 1 gives 5 marks for: MP1: b1 and b2 columns correct ('0010' and '0111' on first row, no other entries); MP2: first value of i is 0; MP3: last three rows of i are 1, 2, 3; MP4: first value of new is '0' (or empty string followed by '0'); MP5: last three rows of new are '01', '010', '0101'. Part 2 gives 1 mark for explaining that strings use 0-based indexing or to prevent out-of-bounds / accessing non-existent index / run-time errors.

Total

Question Part Marking guidance

marks

08 1 5 marks for AO2 (apply) 5

MP1: for b1 column and b2 column correct and no other values in either

column;

MP2: for the first value of i initialised to 0;

MP3: for the last three rows of column i correct and no other values;

MP4: for the first value in new set to '0' or the first value in new set to an

empty string/blank value followed by '0';

MP5: for the last three rows of column new correct and no other values;

Maximum 4 marks if any errors.

b1 b2 new i

'0010' '0111' '' 0

'0' 1

'01' 2

'010' 3

'0101'

I. Different rows used as long as the order within columns is clear

I. Duplicate values on consecutive rows within a columnMARK SCHEME– – –

I. Missing quotes used around strings.

Total

Question Part Marking guidance

marks

08 2 Mark is for AO2 (apply) 251

So the algorithm does not attempt to access a character that does not exist

(in the string);

//

So the algorithm does not attempt to use an index value that is out-of-range;

//

Because indexing (of strings) starts at 0 rather than 1;

A. To make sure it doesn’t crash (when run as a program) ;

A. To prevent a run-time error from happening;

How to answer it

Algorithm Tracing & Zero-Based Indexing

📋 What this question tests

This question assesses your ability to manually trace an algorithm using a trace table and explain string handling principles:

  • Dry-running code: Tracking variables ( b1 , b2 , new , i ) step-by-step through a FOR loop.
  • Boolean logic: Evaluating nested conditions combining OR , AND , and NOT (which effectively performs an XOR operation).
  • String manipulation: Understanding string concatenation ( + ) and string length ( LEN ).
  • Zero-based indexing: Explaining why loop boundaries run to LEN - 1 to prevent out-of-range runtime errors.

Question 08.1 — Algorithm Trace Table

Completing the trace table for the binary string algorithm [5 marks]

📐 Step-by-Step Algorithm Execution

Initialisation (Lines 1–3): b1 = '0010' , b2 = '0111' , new = '' . LEN(b1) = 4 , so i runs from 0 to 3 .

Iteration 1 (i = 0):
b1[0] = '0' , b2[0] = '0' .
Line 5: '0' = '1' OR '0' = '1' → False.
Jump to Line 11 (ELSE): new ← '' + '0' → new becomes '0'.
Iteration 2 (i = 1):
b1[1] = '0' , b2[1] = '1' .
Line 5: '0' = '1' OR '1' = '1' → True.
Line 6: NOT ('0' = '1' AND '1' = '1') → NOT (False) → True.
Line 7: new ← '0' + '1' → new becomes '01'.
Iteration 3 (i = 2):
b1[2] = '1' , b2[2] = '1' .
Line 5: '1' = '1' OR '1' = '1' → True.
Line 6: NOT ('1' = '1' AND '1' = '1') → NOT (True) → False.
Jump to Line 8 (ELSE): new ← '01' + '0' → new becomes '010'.
Iteration 4 (i = 3):
b1[3] = '0' , b2[3] = '1' .
Line 5: '0' = '1' OR '1' = '1' → True.
Line 6: NOT ('0' = '1' AND '1' = '1') → NOT (False) → True.
Line 7: new ← '010' + '1' → new becomes '0101'.

✅ Correct Completed Trace Table

b1 b2 new i
'0010' '0111' '' 0
'0' 1
'01' 2
'010' 3
'0101'

Note: The mark scheme allows leaving quotes out or putting '0' directly on the first row if '' is omitted.

🧠 Mark Breakdown & Exam Technique

  • MP1: Correct initial values for b1 and b2 , and no extra entries in those columns.
  • MP2: First value of i initialised to 0 .
  • MP3: Last three rows of column i correct ( 1 , 2 , 3 ) and no other values.
  • MP4: First value in new set to '0' (or '' followed by '0' ).
  • MP5: Last three values in column new correct ( '01' , '010' , '0101' ) and no other values.
⚠️ Examiner Rule: Maximum 4 marks if there are any errors in the table. Accuracy is vital!

❌ Common Errors in 08.1

  • Repeating unchanged values: Writing '0010' and '0111' on every single row. In standard trace tables, only write a value when it changes.
  • Replacing instead of concatenating: Writing just '1' or '0' in column new instead of appending to the existing string (e.g. writing '1' instead of '01' ).
  • Misreading Line 6: Forgetting that NOT(True AND True) gives False , which diverts to the inner ELSE branch (adding '0' ).

💡 Hidden Concept: Bitwise XOR

Notice what lines 5–10 actually do:

  • If either bit is 1, but NOT both → output '1'
  • If both bits are 0 → output '0'
  • If both bits are 1 → output '0'

This algorithm performs a bitwise XOR (Exclusive OR) operation on two 4-bit binary strings!

Question 08.2 — String Indexing & Bounds

Explain why line 4 uses LEN(b1) - 1 instead of LEN(b1) [1 mark]

✅ Acceptable Answers (Any One)

  • Because string indexing starts at 0 (zero-indexed) rather than 1.
  • So the algorithm does not attempt to access a character/index that does not exist.
  • To prevent an index value that is out of range (index out of bounds).
  • To prevent a run-time error / to prevent the program from crashing.

🧠 Exam Technique: Precise Terminology

String '0010' has a length of 4:

Index01234
Character'0''0''1''0'Does not exist!

If the loop reached i = 4 , accessing b1[4] would trigger an "Index Out of Range" runtime error.

❌ Common Errors in 08.2

  • Too vague: Saying "so it stops at the end" or "because it only has 4 digits" without mentioning zero-indexing, non-existent index, or error/crash.
  • Confusing count with index: Failing to state clearly that the count (length) is 4, but index positions run from 0 to 3.

Topics

3.1 Fundamentals of algorithms · 3.2 Programming · 3.1.1 Representing algorithms · 3.2.2 Programming concepts · 3.2.5 Boolean operations in a programming language · 3.2.8 String handling operations in a programming language

Question and mark scheme from the AQA GCSE Computer Science examination, Paper 1 (1C), June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.