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

6 marks · Medium difficulty · Trace Table

Complete a trace table for an algorithm that processes two binary strings using logical operators and string concatenation, and explain why the loop boundary is indexed up to length minus one.

Practise this question

Question

Question 08 presents Figure 8, containing 15 lines of pseudo-code. Lines 1 to 3 initialise b1 to '0010', b2 to '0111', and new to an empty string ''. A count-controlled loop on line 4 iterates with variable i from 0 to LEN(b1) - 1. Inside the loop, nested selection structures check whether b1[i] = '1' OR b2[i] = '1' and NOT (b1[i] = '1' AND b2[i] = '1'), appending '1' or '0' to new. Part 08.1 asks students to complete an empty trace table with columns labelled b1, b2, new, and i across 8 empty rows. Part 08.2 asks students to 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 The mark scheme for Question 08 part 1 awards 5 marks for completing the trace table: MP1 for correctly setting b1 to '0010' and b2 to '0111'; MP2 for initialising i to 0; MP3 for the remaining values of i (1, 2, 3); MP4 for initialising new to '' and then '0'; MP5 for the subsequent values of new ('01', '010', '0101'). Part 2 awards 1 mark for explaining that strings use zero-based indexing or to avoid accessing an index that is out of range / does not exist.

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

📌 What this question tests

This question assesses your ability to trace pseudo-code algorithms step-by-step using a trace table (evaluating boolean logic including AND , OR , and NOT , as well as string concatenation) and explain zero-based array/string indexing to avoid off-by-one run-time errors.

Question 08.1: Complete the Trace Table

5 Marks • AO2 (Apply)

📐 Step-by-Step Algorithm Walkthrough

Initial state: b1 = '0010' , b2 = '0111' , new = '' .
LEN(b1) is 4, so the loop runs for i = 0, 1, 2, 3 .

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

✅ Completed Trace Table

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

Note: Having '' on the first row or starting directly with '0' is acceptable in the mark scheme. Quotes around strings are also optional.

💡 Mark Breakdown (5 Marks Total)

  • MP1: b1 and b2 columns correct and no other values written in either column.
  • MP2: First value of i correctly initialized to 0 .
  • MP3: Last three rows of column i correct ( 1, 2, 3 ) and no other extra values.
  • MP4: First value in new set to '0' (or empty string '' followed by '0' ).
  • MP5: Last three rows of column new correct ( '01', '010', '0101' ) with no other values.
⚠️ Examiner Note: Maximum 4 marks total if any errors occur within otherwise correct columns.

❌ Common Errors & Pitfalls

  • Repeating unchanged values: Do not write '0010' down every single row of the b1 column! Only write a value when it changes.
  • Replacing vs Concatenating: Writing only the single bit (e.g. '0' , then '1' , then '0' ) instead of appending to the string ( '0' , '01' , '010' , '0101' ).
  • Misreading the logic: The algorithm performs an XOR (exclusive OR) operation: if both bits are '1' , it outputs '0' ; if only one bit is '1' , it outputs '1' ; if both are '0' , it outputs '0' .

Question 08.2: Reason for Using LEN(b1) - 1

1 Mark • AO2 (Apply)

✅ Acceptable Answers (Any 1)

  • Because indexing starts at 0 (zero-based indexing) rather than 1.
  • So the algorithm does not attempt to access a character/index that is out-of-range / does not exist.
  • To ensure the program does not crash / to prevent a run-time error.

🧠 Exam Technique & Examiner Tip

When an exam question asks about loop bounds using LEN() - 1 :

  • State that strings/arrays are 0-indexed.
  • A string of length 4 has indices 0, 1, 2, 3 .
  • Accessing index 4 would cause an "index out of bounds" or "string index out of range" run-time 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 (1A), June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.