OCR A-Level Computer Science Algorithms and programming (02), June 2025: Question 6

18 marks · Medium difficulty · Short Answer

Identify IDE debugging features, explain global vs local variables and parameter passing by value, and identify and correct errors in an array-processing pseudocode algorithm.

Practise this question

Question

Question 6 asks students about programming concepts across multiple parts: (a) A table to identify and describe three debugging features of an IDE (6 marks). (b) Three sub-questions on global and local variables: explaining the difference (2 marks), describing one drawback of global variables (2 marks), and describing one drawback of local variables (2 marks). (c) Describe parameter passing by value (2 marks). (d) An algorithm scenario counting occurrences of numbers 1-9 in an array 'myArray' into a 2D array 'checked', followed by 19 lines of flawed pseudocode. Students must identify the line number and provide a correction for any four errors (4 marks).
Question text

6 A student is writing a program in a high-level programming language.

(a) The student writes the program using an Integrated Development Environment (IDE).

Complete the table by identifying and describing three features of an IDE that the student can

use to debug their program.

Debugging feature Description

[6]

(b) The program the student is developing includes both global and local variables.

(i) Explain the difference between a global variable and a local variable.

… [2]

(ii) Describe one drawback of using global variables in a program.

… [2]

(iii) Describe one drawback of using local variables in a program.

… [2]

(c) A variable can be passed as a parameter into a function by value or by reference.

Describe what parameter passing by value means.

… [2]

(d) An algorithm is needed to count how many times each of the numbers from 1 to 9 appear in an

array called myArray. Another array called checked is used to store each number found in

myArray and the number of times it appears. For example, the contents of myArray are:

73 6 7 5 3 2 3 6

Based on these contents in myArray, the contents in checked would be:

–1 0

–1 0

–1 0

–1 0

–1 indicates an unused space in the array as the numbers 1, 4, 8 and 9 have not been found.

The student has written the following pseudocode for this program.

The pseudocode contains several errors.

01 array myArray[9]

02 myArray = [7,3,6,7,5,3,2,3,6]

03 array checked[9,2]

04 checked = [[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],

[-1,0],[-1,0]]

05 numbersFound = 1

06 for x = 0 to myArray.length

07 found = false

08 for y = 0 to checked.length

09 if checked[y,0] == myArray[y] then

10 checked[y,1] = checked[y,1] + 1

11 found = true

12 endif

13 next y

14 if found == true then

15 checked[numbersFound,0] = myArray[x]

16 checked[numbersFound,1] = 0

17 numbersFound = numbersFound + 1

18 endif

19 next y

Identify the line number of any four errors and write the corrected line for each error.

Error 1

Line number …

Corrected line …

Error 2

Line number …

Corrected line …

Error 3

Line number …

Corrected line …

Error 4

Line number …

Corrected line …

[4]

Mark scheme

Show the mark scheme Mark scheme for Question 6: (a) Identifies breakpoints, stepping, variable watch window, or error diagnostics with descriptions. (b)(i) Global accessible throughout program vs local only existing within declared scope. (b)(ii) Drawbacks of global variables: wastes memory, difficult to maintain/trace changes, affects data integrity/modularity. (b)(iii) Drawbacks of local variables: only accessible in subroutine, requires parameter passing/return values. (c) Function receives a copy of variable, original value unaffected/not overwritten. (d) Error corrections: Line 05 (numbersFound = 0), Line 06 (to myArray.length - 1), Line 08 (to checked.length - 1), Line 09 (myArray[x]), Line 14 (if found == false), Line 16 (checked[numbersFound, 1] = 1 or += 1), Line 19 (next x).

6 (a) 1 mark for feature 1 mark for expansion to max 6 e.g. 6 The features must be relevant

to debugging code. Allow other

• Breakpoints suitable examples e.g.

• Stops the program at set positions to check the flow/variable contents highlighting syntax errors must

be justified in terms of giving

• Stepping/step through/into/over error diagnostics.

• Run the code one line at a time to check the flow/variable contents

Mark the row as a whole. A

• Variable Watch window row may contain multiple

• View the variable/data structure contents as the program runs identifications/expansions.

• Error diagnostics Do not allow pretty printing or

auto-complete

• To locate/report/give details about errors

6 (b) (i) 1 mark each to max 2 2 Examples of specific scope

may be given such as function,

• Global variables are accessible throughout the program subroutine, procedure, module

• Local variable only exist within the scope that they are declared in etc.

6 (b) (ii) 1 mark each to max 2 2 First mark for identification and

second mark for linked

• Global variable exists throughout the run-time of the program… expansion

• …wastes memory

• Makes it difficult to maintain…

• …as it’s difficult to understand where variables are changed

• Reduces integrity / accuracy of data…

• ...as a change in one part can impact on another

• Makes it difficult to test/test a single block…

• … as the whole code may need to be run to setup the global variables

• Reduces modularity / joins modules…

• ...therefore modules no longer standalone

6 (b) (iii) 1 mark each to max 2 2 First mark for identification and

second mark for linked

• Data can only be accessed within the subroutine where it is expansion

declared…

• …you have to pass data as parameters BP4 can be a valid expansion

• …you have to handle return values to BP1 and vice-versa.

• Programming can be more complex/time consuming…

• …you have to pass data as parameters

• …you have to handle return values

6 (c) 1 mark each to max 2 2

• The function receives a copy of the variable

• Changes are made to the copy

• Changes don’t overwrite the original value

• The copy is deleted/no longer available when the function ends

6 (d) 1 mark for each error line and correction. 4 Allow equivalent logic for

correction of line 14 e.g

• Line 05 if found != true then

numbersFound = 0

• Line 06

for x = 0 to myArray.length – 1

• Line 08

for y = 0 to checked.length - 1

• Line 09

if Checked[y,0] == myArray[x] then

• Line 14

if found == false then

• Line 16

Checked[numbersFound,1] = 1

or

Checked[numbersFound,1] += 1

• Line 19

next x

How to answer it

IDE Tools, Variable Scope & Algorithm Debugging

📋 What This Question Tests

This question evaluates your foundational knowledge of program development environments and software design practices, followed by applied trace-level debugging skills:

  • IDE Utilities: Specific features designed strictly for debugging (not merely coding/formatting).
  • Variable Scope & Lifetime: The behavioral differences, memory implications, and architectural trade-offs between global and local variables.
  • Subroutine Mechanics: The exact data-handling behavior of passing parameters by value vs. reference.
  • Pseudocode Analysis & Logic Tracing: Spotting boundary errors (off-by-one), loop variable mismatches, inverted boolean conditions, and state initialisation bugs in 2D array traversals.

Part (a) — IDE Debugging Features

Identifying and describing three tools used specifically to debug code [6 Marks]

✅ Acceptable Pairs (Feature + Description)

Any three of the following (1 mark for naming, 1 mark for description):

  • Breakpoints: Halts program execution at a predetermined line/position to allow the developer to inspect current variable values and program flow.
  • Stepping (Step Over / Step Into / Step Out): Executes the program one line of code at a time to monitor changes to variables and flow line-by-line.
  • Variable Watch / Watch Window: Continuously displays the current value of chosen variables or data structures as the program runs.
  • Error Diagnostics / Crash Reports: Locates and reports runtime errors or syntax problems, highlighting where and why execution failed.

❌ Common Errors & Lost Marks

  • Naming non-debugging tools: Giving general IDE features like Auto-complete, Pretty printing / Indentation, or Syntax Colouring without explicitly linking them to runtime error diagnosis. These are code-editing aids, not debugging features.
  • Vague descriptions: Writing "Stepping makes the program step" (repeating the term without explaining that it executes code one statement at a time).
Mark Scheme Note: 1 mark per identified feature, 1 mark for each valid linked description (Max 6). Mark each row as a whole.

Part (b) — Variable Scope & Lifetime

Comparing Global and Local Variables and evaluating their drawbacks [6 Marks total]

(b)(i) Difference between Global and Local Variables [2 Marks]

✅ Correct Answer

  • Global Variable: Accessible and visible throughout the entire program / across all subroutines [1].
  • Local Variable: Accessible only within the specific block, function, or subroutine in which it is declared / has local scope [1].

🧠 Exam Technique: Scope vs Lifetime

Ensure you mention accessibility / scope. While lifetime differs (globals exist during whole execution; locals only while the subroutine is active), OCR's primary mark scheme definition focuses on where they can be accessed.

(b)(ii) One Drawback of Global Variables [2 Marks]

✅ Correct Answer (Point + Linked Expansion)

Any one fully expanded drawback:

  • Memory inefficiency: They remain in memory for the entire runtime of the program [1] → which wastes memory/RAM [1].
  • Maintenance & Debugging: They can be altered by any subroutine at any time [1] → making bugs hard to track down because it is difficult to identify where unintended changes occurred [1].
  • Modular integrity: Subroutines become dependent on external variables [1] → reducing reusability and modularity (cannot easily paste the function into another project) [1].

❌ Examiner Trap: The "1-Mark Stall"

This is a 2-mark "Describe" question. Stating just "It wastes memory" or "It makes code harder to debug" scores only 1 mark. You must give the cause and the effect (linked expansion).

(b)(iii) One Drawback of Local Variables [2 Marks]

✅ Correct Answer (Point + Linked Expansion)

  • Limited accessibility: They can only be accessed within the subroutine where declared [1] → meaning data must be explicitly passed between modules via parameters or returned values, increasing complexity/time [1].

💡 Key Knowledge

Local variables promote data security and modular isolation, but the trade-off is the overhead of writing parameter lists and coordinating return values across multiple call stacks.

Part (c) — Parameter Passing

Describe what parameter passing by value means [2 Marks]

✅ Correct Answer

Any two of the following points [2 Marks]:

  • The subroutine receives a copy of the data / value held by the argument [1].
  • Any changes made to the parameter within the function do not alter the original variable in the calling code [1].
  • The copy is destroyed/discarded when the subroutine execution terminates [1].

💡 By Value vs. By Reference

  • By Value: Pass a duplicate copy. Original is completely protected from mutation.
  • By Reference: Pass the actual memory address pointer. The subroutine acts directly on the original variable.

Part (d) — Pseudocode Error Identification

Identify four error lines and provide corrected pseudocode [4 Marks]

📐 Walkthrough of the Algorithm Logic

The program iterates through myArray (outer loop) and checks whether the current number has already been recorded in a 2D summary array checked[row, col] (inner loop). If found, increment its count; if not found after inspecting all filled rows, add it as a new entry.

✅ Error Identification & Corrections (Select Any 4)

Line Original Erroneous Code Corrected Line & Reason
Line 05 numbersFound = 1 numbersFound = 0
Arrays are 0-indexed; before searching, zero unique numbers have been inserted.
Line 06 for x = 0 to myArray.length for x = 0 to myArray.length - 1
Off-by-one bound error; iterating up to length causes an index out-of-bounds error.
Line 08 for y = 0 to checked.length for y = 0 to checked.length - 1
Off-by-one error on the inner loop array bounds.
Line 09 if checked[y,0] == myArray[y] then if checked[y,0] == myArray[x] then
Outer loop is indexed by x . Comparing against myArray[y] checks the wrong element.
Line 14 if found == true then if found == false then (or if not found then )
A new entry should be appended to checked only if the number was not found.
Line 16 checked[numbersFound,1] = 0 checked[numbersFound,1] = 1 (or += 1 )
Frequency count starts at 1 upon discovering the element for the first time.
Line 19 next y next x
Loop mismatch. The outer loop starts with for x and must close with next x .

❌ Common Student Mistakes

  • Giving line without correction: The mark is awarded for the line number AND the correct code combined.
  • Missing the loop nesting: Misidentifying line 13 vs 19 when diagnosing loop closure errors. Look at the indentation and loop pairings carefully.

🧠 Exam Tip for Pseudocode Debugging

Scan for "the usual suspects" in OCR array-processing questions:
1. Loop upper bounds ( length vs length - 1 )
2. Index variable mixups ( x vs y inside nested loops)
3. Boolean flags inverted ( true vs false )
4. Initial values (0 vs 1).

Topics

1.4 Data types, data structures and algorithms · 2.2 Problem solving and programming · 2.3 Algorithms · 1.4.2 Data Structures · 2.2.1 Programming techniques · 2.3.1 Algorithms

Question and mark scheme from the OCR A-Level Computer Science examination, Algorithms and programming (02), June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.