AQA GCSE Computer Science Paper 1 (1B), 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 the loop limit is LEN(b1) - 1.

Practise this question

Question

Question 08 shows Figure 8 with a 15-line pseudo-code algorithm comparing two 4-character binary strings '0010' and '0111' using a FOR loop from 0 to LEN(b1) - 1 with nested IF statements checking OR and AND conditions, concatenating '1' or '0' to variable 'new'. Part 08.1 asks to complete a trace table with columns b1, b2, new, and i across 8 empty rows for 5 marks. Part 08.2 asks to explain why line 4 uses LEN(b1) - 1 instead of LEN(b1) for 1 mark.
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 allocates 5 marks: MP1 for b1 and b2 columns having '0010' and '0111' with no other values; MP2 for i initialised to 0; MP3 for subsequent values of i being 1, 2, 3; MP4 for new initialised to '' or '0'; MP5 for subsequent new values '01', '010', '0101'. Part 2 awards 1 mark for stating that indexing starts at 0 so an out-of-range index or non-existent character would otherwise be accessed.

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 & String Indexing

What this question tests
  • Dry running algorithms: Accurately tracking string variables and loop counters inside a trace table.
  • Boolean logic inside loops: Evaluating nested conditions involving OR , AND , and NOT (simulating an XOR operation).
  • String concatenation: Building a new string character-by-character ( new ← new + '1' ).
  • Zero-based indexing: Explaining why string traversal loops run from 0 to LEN - 1 .
Question 08.1

Completing the Trace Table

5 Marks • AO2 (Apply)

📐 Step-by-Step Logic Breakdown (XOR Gate Behaviour)

The loop inspects each bit position i from index 0 to 3 . Notice lines 5–13 implement an exclusive OR (XOR): if exactly one character is '1' , append '1' ; otherwise append '0' .

  1. Initial state: b1 = '0010' , b2 = '0111' , new = ''
  2. Iteration i = 0: b1[0] = '0' , b2[0] = '0' . Line 5 is False → branches to ELSE (line 12) → append '0' → new = '0'
  3. Iteration i = 1: b1[1] = '0' , b2[1] = '1' . Line 5 is True; Line 6 is True (not both '1') → append '1' → new = '01'
  4. Iteration i = 2: b1[2] = '1' , b2[2] = '1' . Line 5 is True; Line 6 is False (both are '1') → branches to line 9 → append '0' → new = '010'
  5. Iteration i = 3: b1[3] = '0' , b2[3] = '1' . Line 5 is True; Line 6 is True → append '1' → new = '0101'

✅ Model Solution Trace Table

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

Note: Starting row for new can either begin with '' on the initial line or start directly with '0' . Quotes are ignored by examiners.

🧠 Exam Technique & Mark Breakdown

  • MP1: b1 and b2 columns correct and written once only (no repeated values down the columns).
  • MP2: Initial value of i set to 0 .
  • MP3: Last three rows of column i contain 1, 2, 3 and no extra values.
  • MP4: First value in new is either '' followed by '0' , or starts directly as '0' .
  • MP5: Subsequent values in new correctly show cumulative concatenation: '01' , '010' , and finally '0101' .

❌ Common Pitfalls in Trace Tables

  • Repeating unchanged variables: Do not rewrite '0010' and '0111' on every single row! Only enter values in a cell when that variable changes state.
  • Writing single characters instead of concatenated strings: Writing '0' , '1' , '0' , '1' in column new loses marks. The code states new ← new + ... , which accumulates characters over time.
  • Over-running the loop: In AQA pseudo-code, FOR i ← 0 TO 3 stops after 3 . Do not add 4 into the table!
Examiner Rule: Maximum 4 marks if any error is made across the trace table.
Question 08.2

Explaining String Boundary Limits

1 Mark • AO2 (Apply)

✅ Model Answers (Any 1 of the following)

  • Because strings use zero-based indexing (indexing begins at 0 , not 1 ).
  • To ensure the algorithm does not attempt to access a character/index that is out of range (or does not exist).
  • To prevent a run-time error (or crash) when accessing the string index.

💡 Why LEN(b1) - 1 is Essential

  • The string '0010' has a length of 4 ( LEN(b1) = 4 ).
  • Valid indices are positions: 0, 1, 2, 3 .
  • If the loop ran to LEN(b1) (which is 4 ), the program would attempt to read b1[4] .
  • Since index 4 does not exist, this causes an IndexOutOfBounds run-time exception.

❌ Common Misconceptions

  • Vague responses: Stating simply "so it stops in time" or "because there are 4 items" earns 0 marks. You must explicitly mention zero-indexing, index out of range, or crash/runtime error.
  • Syntax error confusion: Running past the end of a string is a run-time error, never a syntax error!

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 (1B), June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.