Specification point 2.3.1

Algorithms

Exam questions: 44 questions, 509 marks

Question 1

13 marks

1(a) 6 marks

A program makes use of searching and sorting algorithms.
The following incomplete pseudocode algorithm uses a binary search to find the integer numberToFind in the array array. It returns the index of the array or -1 if the integer is not found.

Complete the pseudocode algorithm.

function binarySearch(array,……)
 lowerbound = 0
 upperbound = array.length - 1

 while true
  if(upperbound < lowerbound) then
   return ……
  else
   mid = (upperbound + lowerbound) ……
   if(array[mid] <numberToFind) then
    lowerbound = mid ……
   elseif(array[mid] > numberToFind) then
    upperbound = mid ……
   else
    return ……
   endif
  endif
 endwhile
endfunction
Mark scheme 1(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each completed statement

function binarySearch(array, numberToFind)
lowerbound = 0
upperbound = array.length - 1

while true
if(upperbound <lowerbound) then
return -1
else
mid = (upperbound + lowerbound)DIV 2
if(array[mid] <numberToFind) then
lowerbound = mid + 1
elseif(array[mid] > numberToFind)

then
upperbound = mid - 1
else
return mid
endif
endif
endwhile
endfunction

Guidance

Accept
mid = int((upperbound + lowerbound)/ 2)

Examiner’s Comments

Binary search (in both iterative and recursive form) is a standard algorithm that candidates are expected to be able to code at AS Level. Candidates made a number of common errors including not using integer division (DIV and / were accepted) for the midpoint calculation.

Some candidates returned the value being searched for at the array index rather than returning mid as the index as specified in the question.

Another common error that was made was to update mid by the wrong value, swapping the +1 and -1 round.

out of 6

1(b)

An array stores the following data:

2083316

1(b)(i) 5 marks

Describe how the given data will be sorted into descending numerical order using an insertion sort.

You should refer to the data in this array throughout your answer.

Mark scheme 1(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 5

  • 20 becomes the sorted list / [20] is the sorted list

  • ... take 8 and compare against ...

  • ... it is less than 20 so keep it in place / [20 8] is now the sorted list

  • Take 33 and compare it to each value in the sorted list. It is greater than 20, so move 20 and 8 and insert 33 / 33 is compared and moved down and [33 20 8] is now the sorted list

  • Repeat for all other elements.

Guidance

Max 4 if ascending and not descending

Zero marks if not provided a description and just shown data values

Examiner’s Comments

Insertion sort is one of the standard sorting algorithms that candidates need to be familiar with using. A pleasing number of candidates made a reasonable start to the

response, but fewer could produce a comprehensive response.

The question required candidates to describe and not just show how insertion sort worked, so responses that only gave diagrams showing numbers moving with no annotation did not gain credit. Some candidates mistakenly described bubble sort or merge sort.

Quite often, where candidate scored four marks, they omitted the first pass of the sort where the first item (20) is set as the sorted list. Some potentially quite good responses were too vague as to how the next item at the start of the next pass filtered back through the sorted list to its correct position.

out of 5

1(b)(ii) 2 marks

The size of the array has now been increased to seven elements.

The insertion sort algorithm needs to be tested to ensure it sorts a range of test data into descending numerical order.

For example, the test data in the array here will test to see if the insertion sort will sort data in the opposite order.

1234567

Give two other different sets of data in the array that can be used to test the insertion sort and state the purpose of each set of test data.

Each test needs to have a different purpose.

Set One

Test Data 1

Purpose of test data 1

Set Two

Test Data 2

Purpose of test data 2

Mark scheme 1(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each set of test data and purpose
e.g.

  • Test Data: 7 6 5 4 3 2 1 Purpose: Testing that data is already in order

  • Test Data: 1 7 2 6 3 5 4 Purpose: Testing that mixed data is sorted

  • Test Data: Six One Seven Three Four Fix Two

  • Purpose: Testing that words are rejected/ Testing words are sorted (alphabetically)

  • Test Data: -1, 0, 2, -1, 3, -3

  • Purpose: Testing the algorithm works with negative numbers.

Guidance

Each purpose must be different.
Accept viable alternatives

The purpose must be relevant to the test data given.

A mark cannot be award unless both the test data and purpose are given.

Examiner’s Comments

Many candidates gained some credit for giving a valid reason for a set of test data that they presented. Clear responses included testing decimals, negatives, different data types, and testing on data

that was not already in order.

out of 2

Question 2

2 marks

2 2 marks

A programmer is designing a program that will store data.

The programmer is deciding whether to store the data in a stack or a queue.

Identify one similarity and one difference between a stack and a queue.

Similarity

Difference

Mark scheme 2

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for similarity:

  • Both are data structures / store data

  • Both allow data to be added/removed

  • Both have identifier(s) / pointer values

1 mark for difference:

  • Stack is LIFO and queue is FIFO

  • Queue supports enqueue/dequeue operations whilst stack supports push/pop operations

  • Queue require two pointers whilst stacks only require one pointer

Guidance

Examiner’s Comments

Most candidates demonstrated knowledge of the purpose of stacks and queues. For the similarity, a frequent response was that both stacks and queues are data structures used to store data. For the difference, most candidates identified that a stack was a LIFO structure while a queue was a FIFO structure.

out of 2

Question 3

9 marks

3 9 marks

Kofi and Zac both write a different pseudocode algorithm to read the data from a text file into an array.

Kofi's Algorithm

fileName = "data.txt"
fileToRead = openRead(fileName)
for x = 0 to 1000
 anyData = fileToRead.endOfFile()
 if NOT anyData then
  x = 1001
 else
  dataValue = fileToRead.readLine()
  array[x] = dataValue
 endif
next x
fileToRead.close()

Zac's Algorithm

function readData(fileName)
 array data[100]
 x = 0
 fileToRead = openRead(fileName)
 while NOT fileToRead.endOfFile()
  data[x] = fileToRead.readLine()
  x = x + 1
 endwhile
 return data
endfunction

The solution needs to be used in different programs. Each program will use a different text file where the number lines in the text file is unknown.

Compare the suitability of each algorithm for the given problem.

You should include the following in your answer:

  • the suitability of the programming techniques including the use of loops
  • how effectively the solution meets the requirements.
Mark scheme 3

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3-High Level
(7-9 marks)
The candidate demonstrates thorough knowledge and understanding of suitability of algorithms; the material is generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided. Evidence/examples will be explicitly relevant to the explanation. The candidate provides a thorough discussion which is well-balanced. Evaluative comments are
consistently relevant and well-considered.
There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2-Mid Level
(4-6 marks)
The candidate demonstrates reasonable knowledge and understanding of suitability of algorithms; the material is generally accurate but at times underdeveloped.
The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate provides a reasonable discussion, the majority of which is focused. Evaluative comments are for the most part appropriate, although one or two opportunities for development are missed.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence.

Mark Band 1-Low Level
(1-3 marks)
The candidate demonstrates a basic knowledge of suitability of algorithms, with limited understanding shown; the material is basic and contains some inaccuracies. The candidate makes a limited attempt to apply acquired knowledge and understanding to the context provided.
The candidate provides a limited discussion which is narrow in focus. Judgments if made are weak and unsubstantiated. The information is basic and communicated in an
unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 mark
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding e.g.

  • Kofi’s algorithm reads data from the text file and writes these value to an array. It cannot be called by different programs, doesn’t work with different text files and does not consider the number of items in the file.
  • Zac’s program also reads data from the text file and writes these values to an array. It can be called by different programs, works with different file names and does consider the number of items in the file.

AO2.1: Application e.g.
Kofi's algorithm:

  • Has additional/unneces sary variables
  • ...e.g. fileName, dataValue
  • Loops 1000 times which is inappropriate when it needs to be used with unknown quantity
  • Will not read any lines after the first 1000

Zac's algorithm:

  • Uses a function so that is can be used in different programs / is independent
  • Takes file name as parameter so that it can be called with different files
  • The array size is 100. Therefore, if the data being read is greater than 100 the program will crash.
  • Does not close the file

AO3.3: Evaluation e.g.

  • Zac's is more memory efficient as it uses fewer variables
  • Kofi's is more suitable in that it closes the file so it does not remain open in memory
  • Zac's is more suitable to be used in different

programs due to function and not hard coding the file name

  • Zac’s is easier to alter for a different file size as fewer lines of code would need to be altered

Examiner’s Comments

There were a large number of either blank or very brief responses where candidates displayed no ability to read and interpret code. The question source material was designed to help candidates to comment on a range of programming practices such as file opening and closing, conditional versus count- controlled loops and the benefits of the use of functions with parameters.

Level 1 responses often just focused on the use of two different loop types. There were few Level 3 responses that gave insightful evaluative comments. Where candidates were able to do so they often focused on memory usage or the ability to cope with different data sets that could be read.

Exemplar 2

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

Kari's Algorithm
function find_file(filename)
    file_found = false
    for i = 0 to length(files) - 1 do
        if files[i].name == filename then
            file_found = true
            return files[i]
        else
            file_found = false
        end if
    end for
    return file_found == true ? null : "file not found"
end function

Zara's Algorithm
function find_file(filename)
    array data[100]
    for i = 0 to 99 do
        if data[i] == filename then
            return data[i]
        end if
    end for
    return "file not found"
end function

The solution needs to be used in different programs. Each program will use a different list for where the number lines in the file are located.

Compare the suitability of each algorithm for the given problem.

You should consider the following in your answer:

  • the suitability of the programming technique including the use of loops
  • how efficiently the solution meets the requirements

A candidate's handwritten answer:

Kari's algorithm uses big O(n) time complexity. "file_found" is set to true, but the "file_found" variable is set to false in every loop. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found, the program will continue to loop and set "file_found" to false until it reaches the end of the list. This means that if the file is found,

This response showed that the candidate has thought about the issues related to the question and had carefully annotated the code when analysing it.

The response was well- structured taking each of the algorithms in turn and displayed a clear level of evaluative insight.

out of 9

Question 4

6 marks

4(i) 2 marks

A sorting algorithm has a best time complexity of O(n).
Describe what is meant by the best time complexity O(n) for a sorting algorithm.

Mark scheme 4(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Linear

  • The time will (increase) in direct proportion to the number of items

Guidance

Examiner’s Comments

Many candidates did not identify linear but gave a description for ‘directly proportional’ or vice-versa, so only gained one mark. Candidates needed to specify that the time required increased in direct proportion to the number of items. Proportion on its own was too vague and could have meant inverse proportion

for example.

Incorrect responses included ‘quickest time to find / least operations’ defining best case rather than answering the question regarding O(n).

out of 2

4(ii) 2 marks

Another sorting algorithm has a worst space complexity of O(log(n)).

Describe what is meant by the worst space complexity O(log(n)) for a sorting algorithm.

Mark scheme 4(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Logarithmic

  • The additional memory space required grows at a decreasing rate as the number of items increases

Guidance

Examiner’s Comments

Many candidates did not identify logarithmic but tried to give a description or vice-versa. Many candidates just said the memory space increased in proportion to the log of n without explaining what this meant. For the second mark candidates had to explain that as the number of items n increased the amount of additional memory required became progressively smaller.

out of 2

4(iii) 1 mark

Identify the time complexity that means the time will not change even when the number of items increases.

Mark scheme 4(iii)

Constant / O(1)

Guidance

Examiner’s Comments

The vast majority of candidates gave the correct response of constant or O(1).

4(iv) 1 mark

Identify the space complexity that means the amount of memory (space) used will double each time a new item is included.

Mark scheme 4(iv)

Exponential / O(2n) / O(Kn)

Guidance

Examiner’s Comments

Half the candidates correctly identified exponential complexity, but common erroneous responses included O(n2) or O(2n) instead of O(2n).

[An examiner's marking symbol, not shown here.]

Misconception

A number of candidates

erroneously thought that n2 or 2n demonstrated exponential growth instead of 2n. Candidates need to have the mathematical grounding to understand the difference between different Big O growth factors.

Question 5

13 marks

5(a) 2 marks

A computer game stores tasks that the player has requested. Each task has:

  • an identification (ID) number e.g. Task A
  • a real number to be processed e.g. 123456.789
  • an integer number to represent the order the tasks should be accessed e.g. 1.

The task that needs to be processed the earliest is given the order number 1.

Two or more tasks can have the same order number. For example, two tasks can have an order number 1.

The data about each task needs to be stored. This will store the ID number, data value and order number for a task.

Explain why a record data structure is suitable for this data.

Mark scheme 5(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 2 for justification e.g.

  • Can store multiple items of data under one identifier / so all the data about a task can be accessed using the same identifier

  • Can store data of different data types and this task has string, real and integers

Guidance

Examiner’s Comments

Record structures were poorly understood, and it was clear that many candidates had very limited experience of using records / structures within a programming language. Many candidates gave responses related to database records rather than record data structures.

out of 2

5(b)

The tasks will be stored in a binary search tree before they are processed. They are stored in ascending order by their order number.

5(b)(i) 2 marks

Give two characteristics of a binary search tree.

1

2

Mark scheme 5(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each e.g.

  • Each node can have 0, 1 or 2 child nodes / a maximum of 2 child nodes

  • Nodes are ordered (with left nodes less than the parent and right nodes greater)

  • The location to which a node is added depends on its order.

Guidance

Examiner’s Comments

Some candidates gave generic properties of trees such as ‘root’ instead of specific characteristics of a binary search tree as required by the question. There was then some lack of precision when describing the number of child nodes each parent node could have (maximum two, not always two), or lack of clarity in defining ‘ordered’ without qualifying what this meant.

out of 2

5(b)(ii) 1 mark

Give an advantage of storing the tasks in a binary search tree instead of a 1-dimensional array.

Mark scheme 5(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for advantage e.g.

  • Searching is faster ( O(log n) )

  • Inserting new tasks is faster

  • Do not need to sort the structure (each time a new task is inserted)

Guidance

Examiner’s Comments

A number of candidates erroneously talked about

binary tree traversal to traverse a 1D list. However, there were many clear and correct responses. Some unqualified ‘easier’ / ‘quicker’ type responses gained no credit. Candidates had to identify that it was quicker to search/insert into the tree.

out of 1

5(b)(iii) 5 marks

Tick (✓) one column in each row to identify whether each statement applies to a depth-first (post-order) tree traversal, a breadth-first tree traversal, or neither of these two traversals, when performed on a binary search tree.

StatementDepth-first (post- order)Breadth-firstNeither of these two traversals
All nodes at the current depth are visited before moving to the next depth
The algorithm traverses to the end of one branch before moving to another branch
The algorithm will make use of backtracking
The traversal can be used to output the contents of the tree in ascending order
The algorithm will output the root node last
Mark scheme 5(b)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each row

StatementDepth-first (post-order)Breadth-firstNeither of these two traversals
All nodes at the current depth are visited before moving to the next depth✓
The algorithm traverses to the end of one branch before moving to another branch✓
The algorithm will make use of backtracking✓
The traversal can be used to output the contents of the tree in ascending order✓
The algorithm will output the root node last✓

Guidance

Examiner’s Comments

Many candidates achieved at least partial credit if not full credit.

out of 5

5(b)(iv) 3 marks

The tasks currently stored in the binary search tree are shown here.

When a new task is inserted with the same order number as a pre-existing task, it is classed as having a higher order number.

For example, task G has the same order number as task A. Since task G was inserted after task A it is classed as a higher number.

Change the diagram to show the contents of the binary search tree after the following tasks are inserted in the order given:

  • Task X with order number 12
  • Task Y with order number 7
  • Task Z with order number 11

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["Task A<br/>Order 6"] ---|left| B["Task B<br/>Order 3"]
    A ---|right| D["Task D<br/>Order 9"]
    B ---|left| E["Task E<br/>Order 1"]
    B ---|right| C["Task C<br/>Order 5"]
    E ---|left| I["Task I<br/>Order 2"]
    D ---|left| F["Task F<br/>Order 7"]
    D ---|right| H["Task H<br/>Order 10"]
    F ---|left| G["Task G<br/>Order 6"]
Mark scheme 5(b)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for Task Y to right of Task F
1 mark for Task X to right of Task H …
… 1 mark for Task Z to left of Task X

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["Task A<br/>Order 0"] ---|left| B["Task B<br/>Order 3"]
    A ---|right| D["Task D<br/>Order 9"]
    B ---|left| E["Task E<br/>Order 1"]
    B ---|right| C["Task C<br/>Order 5"]
    E ---|left| I["Task I<br/>Order 2"]
    D ---|left| F["Task F<br/>Order 7"]
    D ---|right| H["Task H<br/>Order 10"]
    F ---|left| G["Task G<br/>Order 6"]
    F ---|right| Y["Task Y<br/>Order 7"]
    H ---|left| X["Task X<br/>Order 13"]
    X ---|left| Z["Task Z<br/>Order 11"]

Guidance

The direction of left/right child nodes must be clear and cannot just be a downward vertical line.

Examiner’s Comments

The binary search tree diagram generally was answered well with the majority of candidates gaining full marks.

out of 3

Question 6

40 marks

6(a) 3 marks

A game is being written that makes use of object-oriented programming. A prototype for one part of the game is being designed that includes a character, a road and a prize to collect.

The road will have 50 spaces that a character can move along. Each space on the road will store a null value or a prize object for the user to collect. Each space is numbered sequentially from the first space (position 0) to the last space (position 49) and will not change during the game. As the player travels down the road, the position the player is on the road will be output.

The road is designed to be a 1-dimensional array with the identifier road.

Explain why an array is a suitable data structure to represent the road.

Mark scheme 6(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 3. Max 2 for generic answers with no relation to scenario. e.g.

  • Has a set/fixed number of values

  • …and the number of spaces in the road will not change

  • Stores data of one type

  • … as the array is only made up of prize objects

  • Stores data linearly

  • … match the linear nature of the road

  • Array contents are mutable

  • … so prizes can be added/removed from the road

  • A single indentifier is used to directly index

  • … any position in the road

  • Can be iterated by index

  • … to perform an operation on all road positions

Guidance

Examiner’s Comments

Many responses were too vague, showing little knowledge of the properties of arrays. Relatively few candidates appeared to be able to make explicit links to the scenario to achieve full marks.

out of 3

6(b)

The characters and prizes are designed as separate classes. 10 of the spaces on the road will contain an instance of the class Prize. The other spaces will be empty.

The class design for Prize is here.

class: Prize
attributes:
private name : string
private type : string
private value : integer
methods:
new()
getName()
getType()
getValue()

new() is the constructor method. The name, type and value are passed to the constructor as parameters which then assigns these to the attributes.

6(b)(i) 2 marks

The method getName() returns the data in the attribute name.
Write the method getName() using pseudocode or program code.

Mark scheme 6(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Function/subroutine with identifier getName taking no parameters

  • Returning name

e.g.

public function
def getName(self):
getName()
return name            return self.__name
endfunction
public getName(){      function getName() {
return name            return this.name

} }

Guidance

BP1 Do not award procedure or method

BP1 Allow self as an additional parameter if Python is used.

BP1 If an access modifier is given for the method, it must be public and not private.

BP2 Do not allow any modified name attribute to be returned.

Examiner’s Comments

While many candidates had little difficulty giving code for a getter() there were a number of common errors. Some candidates used a private access modifier when a getter() needs to be public. There was often erroneous use of ‘procedure’ whereas a getter() is a function that must return a value. Some candidates tried to set values within the getter() function when it should only have returned the class attribute value.

out of 2

6(b)(ii) 3 marks

A global 1-dimensional array, allPrizes, stores 10 objects of type Prize.

The prize in index 3 has the name “Box”, the type is “money” and the value is 25.

Write pseudocode or program code to create a new object for this prize and store it in index 3 of

allPrizes.
Mark scheme 6(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • New instance of prize …

  • … with “Box”, “money” and 25 as parameters

  • Assigned to allPrizes index 3

e.g.

allPrizes[3] = new prize("Box", "money", 25)
allPrizes[3] = prize.new("Box", "money", 25)
allPrizes[3] = prize("Box", "money", 25)

Guidance

MP2 allow any order of parameters

"Box" and "Money" must be strings and 25 must be an integer

Allow prize.new() as new is given as the constructor method in the class diagram

Examiner’s Comments

Many candidates struggled with the instantiation of an object. Where candidates made an attempt to instantiate some did not use a string for “box” and “money” or did not give 25 as an integer but instead gave the string “25”.

out of 3

6(b)(iii) 3 marks

The game starts with 10 prizes. Each prize is allocated to one space on the road.

An algorithm needs designing that will generate a random space on the road for each prize. Each road space can only store one prize.

Describe the decisions that will need to be made in this algorithm and how these will affect the program flow.

Mark scheme 6(b)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each bullet to maximum 3 e.g.

  • Decision - check whether the space already has a prize allocated …

  • Action if true - another space/number will need to be generated

  • Action if false - the prize will be stored here

  • Decision - check if all 10 prizes have been allocated …

  • Action if true - the algorithm needs to stop generating numbers

  • Action if false - a new number/space needs to be generated and checked

Guidance

Give:

  • 1 mark for stating a decision
  • 1 mark for the action required if true
  • 1 mark for the action required if false

Examiner’s Comments

There were only two reasonable decisions that could be given from the scenario details. Candidates needed to make it clear that a decision with a Boolean output was present that would dictate two potential outcomes. Some candidates quoted actions such as ‘randomly assign space for prize’ which did not represent a decision. Many responses described the mechanics of setting up the game and

the random spaces but did not highlight the program conditions/decisions as required.

out of 3

6(c)

The class design for Character is here.

class: Character
attributes:
private name : string
private money : integer
private experience : integer
private roadPosition : integer
methods:
new()
getName()
getMoney()
getExperience()
getRoadPosition()
changePosition()
updateValues()

The four get methods return the associated attribute.

The number of moves is passed to changePosition() as a parameter. The method adds this value to the character’s position on the road.

The type and value of an object are passed to updateValues() as parameters. If the object is money the value is added to the character’s money. If the type is experience the value is added to experience. If the type is neither money or experience no changes are made.

6(c)(i) 5 marks

new() is the constructor method. The name of the character is passed into the constructor as a parameter. The constructor then initialises both the experience and road position of the character to 0 and initialises the amount of money to 5.

Write the constructor method for Character using either pseudocode or program code.

You do not need to declare the class, the attributes or any other methods.

Mark scheme 6(c)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Constructor header (any suitable name e.g. new, constructor, create, init)

  • …taking one parameter only

  • Initialising name to the parameter

  • Initialising money to 5

  • Initialising experience to 0 and roadPosition to 0

e.g.

public procedure new(pName)
name = pName

Pseudocode experience = 0
example: roadPosition = 0

money = 5
endprocedure
def __init__(self, pName):
self.__name = pName

Python

self.__experience = 0

Example:

self.__roadPosition = 0
self.__money = 5
public Character(string pName)
{
string name = pName;

C# Example: int experience = 0;

int roadPosition = 0;
int money = 5;
 }

Guidance

Allow minor changes to identifiers as long as purpose is clear.

Allow

procedure
new(pName)
this.name = pName

…
(or similar e.g. self.name)

Allow two parameters if one is self and the response is clearly in Python.

The parameter name should be different to the attribute name.

Examiner’s Comments

It was clear that those candidates with limited OOP programming knowledge found the writing of a relatively simple constructor method difficult. Those with relevant programming experience often found this to be a very straightforward question. Common errors included passing additional values to set the experience,

roadPosition and

money attributes rather than setting them to the constant values indicated in the question.

out of 5

6(c)(ii) 5 marks

The type and value of a prize are passed as parameters to the method updateValues. If the type is money the value is added to the character’s money. If the type is experience then the value is added to the experience. If the type is neither money or experience no changes are made.

For example, for the Character player1:

player1.updateValues("money",10) updates player1’s money by 10

player1.updateValues("experience",5) updates player1’s experience by 5

player1.updateValues("foo",9) has no effect on player1.

Write pseudocode or program code for the method updateValues().

Mark scheme 6(c)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Procedure/method header …

  • … taking two parameters, type (or similar) followed by value (or similar) …

  • … compare type parameter with "money"

  • … compare type parameter with "experience"

  • … both attributes updated correctly and nothing else modified

e.g.

public procedure updateValues(pType, pValue)
if pType == "money" then
money = money + pValue
elseif pType == "experience"
experience = experience + pValue
endif
endprocedure

def updateValues(self, pType, pValue):
if pType == "money":
money += pValue
elif pType == "experience":
experience += pValue

Guidance

Do not allow Function for BP1

BP2 parameters must be given in the correct order to match the calls to updateValues() in the question.

“money” and
“experience” must be string values

Examiner’s Comments

The updateValues

procedure again proved problematic for candidates with limited OOP experience. No marks were given for the first mark point if a function was declared as there was no return value. Parameter names needed to be fit for purpose, understandable, and had to match the order given in the question scenario to work for the given example calls.

out of 5

6(d) 6 marks

This incomplete pseudocode algorithm:

  • creates a new character with the name Jamal
  • loops until the character reaches the end of the road
  • generates a random number of spaces to move between 1 and 4 (including 1 and 4)
  • moves the character and checks if the new space has a prize
  • updates the character attributes if there is a prize
  • outputs the character’s new attribute values.

Complete the pseudocode algorithm.

character1 = new …… ("Jamal")
newPosition = 0
while newPosition < ……
  move = random(1, 4) /this will generate a random number between 1 and 4
  character1.changePosition(move)
  newPosition = character1.getRoadPosition()
  if newPosition < 50 and road[……] != null then
    prizeType = road[newPosition].getType()
    valueAmount = road[newPosition].getValue()
    character1.updateValues(……, valueAmount)
    print("Congratulations you are in position", newPosition, "and found",
      road[newPosition].getName())
    print("Money =", character1.getMoney(), "and experience =",
      character1. …… ())
  endif
……
print("You reached the end of the road")
Mark scheme 6(d)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each completed space

character1 = new Character("Jamal")
newPosition = 0
while newPosition < 50
move = random(1, 4)
character1.changePosition(move)
newPosition = character1.getRoadPosition()
if newPosition < 50 and road[newPosition] !=
null
then
prizeType = road[newPosition].getType()
valueAmount = road[newPosition].getValue()
character1.updateValues(prizeType,
valueAmount)
print("Congratulations you are in position",
newPosition, "and found",
road[newPosition].getName())
print("Money", character1.getMoney(), "and
experience", character1.getExperience())
endif
endwhile
print("You reached the end of the road")

Guidance

Allow road.length / len(road) instead of 50

Allow <=49 instead of <

50

Examiner’s Comments

Nearly all candidates achieved some marks, and a majority scored five or six marks.

out of 6

6(e) 4 marks

The procedure displayRoad() outputs the contents of each space in the road. The number of each space is output with either:

  • the word “empty” if there is no prize
  • the name of the prize if there is a prize.
01  procedure displayRoad()
02     for x = 0 to 60
03        print("Space", y)
04        if road[x] == null then
05         print("empty")
06        elseif
07         print(road[x].getValue())
08        endif
09     next x
10  endprocedure

The algorithm contains errors.

Give the line number of four different errors and write the corrected line for each error.

Error 1

Error line 1

Correction

Error 2

Error line 2

Correction

Error 3

Error line 3

Correction

Error 4

Error line 4

Correction

Mark scheme 6(e)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • (Line 02) for x = 0 to 49

  • (Line 03) print("Space", x)

  • (Line 06) else / elseif road[x] <> null

  • (Line 07) print(road[x].getName())

Guidance

Line 07 allow

print(road[x].name)

Examiner’s Comments

Many candidates scored three or four marks but in

general candidates found it harder to identify errors in the code than to complete code in the previous question. Some candidates didn’t give the line number but rewrote the incorrect line before giving the corrected line, which was acceptable, although not ideal given the scaffolding.

out of 4

6(f) 9 marks

A programmer is going to create a prototype for one small part of the game. Both road and allPrizes will be needed throughout the whole prototype. The programmer is considering making these global arrays as she thinks it will reduce the development time. Another programmer has suggested that doing this may create some problems when the rest of the game is created at a later stage.

Compare the use of global and local variables in this program.

You should include the following in your answer:

  • the use of local and global variables
  • alternative methods to using global variables
  • the appropriateness of each to this program design.
Mark scheme 6(f)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level (7-9 marks)
The candidate demonstrates a thorough knowledge and understanding of global variables and the alternatives; the material is generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided. Evidence/examples will be explicitly relevant to the explanation. There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level (4-6 marks)
The candidate demonstrates reasonable knowledge and understanding of global variables and the alternatives; the material is generally accurate but at times underdeveloped. The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate provides a reasonable discussion, the majority of which is focused. Evaluative comments are, for the most part appropriate, although one or two opportunities for development are missed.

There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence.

Mark Band 1 – Low Level (1-3 marks)
The candidate demonstrates a basic knowledge of global variables and the alternatives with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and understanding to the context provided. The candidate provides a limited discussion which is narrow in focus.
Judgements if made are weak and unsubstantiated.

The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 mark
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding Indicative content

  • Global variables are created when the program starts, all subroutines can access/update the contents
  • Local variables are created in the subroutine they are created in, they are not accessible directly from any other subroutine
  • Local variables are removed from memory when the subroutine ends.
  • Local variables can be passed as parameters to a function to be updated, and then returned to override the original local variable
  • Local variables can be passed by reference to a subroutine to allow the content of the variable to be updated

AO2: Application

  • The variables will be stored in memory throughout the whole code execution. However, the amount of data they are storing is relatively low so would not use a lot of memory.
  • When the game is expanded, the amount of data may increase so it could be memory intensive, especially if graphics are used in the game.
  • Both arrays are needed throughout the whole game so keeping them as global will make writing the code easier as the programmer will not need to keep passing them as parameters and setting return values.
  • Only one part of the game is being created initially and therefore the use of global variables would not affect the efficiency greatly. However, when the program expands, it could cause accuracy / testing / debugging and maintenance problems.

AO3: Evaluation

  • As this is only a prototype, the use of global variables would be beneficial.
  • However, when the game expands, the use of global variables could create issues such as running out of memory, coupling, testing & debugging problems and maintenance problems.
  • The programmer may be best to keep the variables as local and then pass them between the different subroutines as parameters byVal and byRef.

Examiner’s Comments

Most responses were Level 2 for definitions and some expansion to passing parameters. Very few candidates were able to go into depth about alternatives to global variables such as passing by value and passing by reference in detail or extending to issues such as scalability within a larger more extended game. Few candidates picked up on the fact that this was a more limited prototype that was likely to be expanded on which would require more consideration to be given to variable scope.

out of 9

Question 7

11 marks

7(a) 7 marks

A computer game has a building containing 7 rooms. There are secret passages between each room. Fig. 3 shows the rooms and the passages between the rooms represented as a graph data structure.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

graph LR
    A["90"] ---|20| B["80"]
    A ---|44| C["43"]
    B ---|13| D["70"]
    B ---|56| E["20"]
    C ---|22| E
    D ---|62| E
    D ---|80| G["0"]
    E ---|15| F["8"]
    F ---|9| G

Fig. 3

The number in bold below each node in Fig. 3 is the heuristic value.

Perform an A* algorithm on the graph shown in Fig. 3 to find the shortest path from A to G.

Show your working, the nodes visited and the distance.

You may use the table below to give your answer.

NodeDistance travelledHeuristicDistance travelled + HeuristicPrevious node

Final path: ……
Distance: ……

out of 7

7(b) 4 marks

State four ways that a graph data structure is different from a tree data structure.

1

2

3

4

Mark scheme 7(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each difference up to a maximum of 4 marks: e.g.

  • Trees have one root node / graphs do not have a root node (1)

  • Trees do not allow cycles/loops / graphs do allow cycles / loops (1)

  • Trees store hierarchy / graphs have no hierarchy (1)

  • Trees are always undirected / graphs can be directed (1)

  • Trees are always connected / graphs can be connected or disconnected (1)

Guidance

Do not allow responses related to weighted / unweighted.

Examiner’s Comments

Most candidates struggled to score more than one or two marks for this question. Responses had to be clearly mappable to technical terms, but there was evidence of vague language in many cases. Candidates were expected to be able to talk about root nodes, cycles, hierarchy,
directed/undirected edges and
connected/disconnected nodes. Clear use of technical terms is expected at this level. A common incorrect response was

weighted/unweighted. A minimum spanning tree is a subset of a graph that can have weighted edges.

out of 4

Question 8

6 marks

8(a) 2 marks

The current contents of a queue data structure are shown in Fig. 4.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

201532

headPointer points to the first cell (containing 20). tailPointer points to the fifth cell (which is empty).

Fig. 4

State the purpose of headPointer and tailPointer in the queue shown in Fig. 4.

headPointer
tailPointer
Mark scheme 8(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • headPointer to identify the first item/element in the queue / identify which item to dequeue/remove next

  • tailpointer to identify the next free space in the queue / identify where the next item/element will be enqueued/added

Guidance

Examiner’s Comments

This question was generally well answered by many candidates. There were some vague responses such as ‘start of queue’, which was not precise enough to indicate the first item, or the index of the first item, as distinct to the indexes of the actual data structure itself.

out of 2

8(b) 2 marks

enqueue will add data to the queue. dequeue will remove data from the queue.

Show the contents of the queue and the position of both pointers after the following actions have been executed on the queue shown in Fig. 4 in the order given:

• enqueue(20)
• dequeue()
• dequeue()
Mark scheme 8(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for queue elements
1 mark for both pointers

Guidance

Allow 20 and 15 in place but crossed out OR allow 20 and 15 in place only if headPointer and tailPointer are correct

Examiner’s Comments

Most candidates either tended to score full marks or no marks. Many candidates missed labelling the pointers in their diagrams and just gave updated queue values. Some candidates kept the values 20 and 15 on the diagram and correctly moved the headPointer to point to index 3 and the tailPointer to the next free space available. A considerable number of candidates erroneously shifted all items forward, showing a lack of understanding as to how a queue is efficiently implemented.

out of 2

8(c) 2 marks

The queue is used to store ID numbers of jobs that a program needs to process. Some jobs will be given a priority which means they need to be processed first.

Explain why this queue is not a suitable data structure for this program.

Mark scheme 8(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 2 e.g.

  • A queue is a FIFO structure / elements processed in the order entered

  • A queue will not allow new data inserted at the front / only allows new data to be enqueued at the rear

  • The queue contents cannot be resequenced/sorted without rewriting

Guidance

Examiner’s Comments

The first part of many responses was well attempted, with most candidates identifying the First In First Out (FIFO) property of a queue. Far fewer candidates were able to successfully expand on this for the second mark. A linked explanation was required such as a higher priority item cannot be inserted at the front/in the middle of the queue because only the first element can be accessed/dequeued. Some candidates just reiterated what FIFO meant instead of giving the linked explanation to a priority queue which was insufficient to gain the second mark.

out of 2

Question 9

12 marks

9(a) 4 marks

The contents of a stack are stored in the 1-dimensional array called numbers.

topStack stores the index of the next free space in the stack.

The array is declared with space for 100 elements.

The function pop() returns the next item from the stack and updates the appropriate pointers.

Describe the steps in the function pop().

Mark scheme 9(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Check if the stack is empty / check topStack is equal to 0

  • …and if so return a suitable value (e.g. -1/ null) / do nothing /give warning

  • (If not empty) decrement topStack

  • Return the value in element topStack from the array numbers

Guidance

Do not award BP3 if a value has been returned from the function for BP4 first.

Examiner’s Comments

There were many weak responses that did not outline the discrete steps required in the pop() function and there was often no reference to the topStack pointer.

A number of candidates confused a stack with a queue and talked about head/rear pointers. Some candidates confused ‘space for 100 elements’ in the question with the top of the stack and then

erroneously talked about removing item 100.

Some candidates erroneously stated that the value at topStack - 1 would be returned before saying that topStack would be decremented. The order of the steps was important for the function to operate correctly, and many candidates lost a mark due to this.

Exemplar 2

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

A candidate's handwritten answer:

Describe the steps in the function pop().

  1. Check if stack is empty, if yes return an error as popping is empty.
  2. get to top stack - a value and [unclear] the value and deletes it from the stack
  3. move pointer at top stack to top stack - a -> top stack = top stack - a

This response shows the candidate returning the value from topStack - 1 in step 2. As soon as the function returns a value no further actions are performed within the function, so decrementing topStack in point 3 was not given.

out of 4

9(b) 4 marks

The function push() inserts its parameter called dataValue onto the stack and updates the appropriate pointers.

Complete the function push() using pseudocode or program code.

function push(... ……)
   if …… ! = 100 then
     numbers [……] = dataValue
     topStack = topStack + ……
     return true
   else
     return false
   endif
endfunction
Mark scheme 9(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each completed statement

function push (dataValue)
if topStack != 100 then
numbers[topStack] = dataValue
topStack = topStack + 1
return true
else
return false
endif
end function

Guidance

Examiner’s Comments

The majority of candidates scored three or more marks. Some candidates erroneously used

numbers.length or

len(numbers) in the second space instead of

topStack.
out of 4

9(c) 4 marks

Write an algorithm, using pseudocode or program code, to call the function push() with the value 15 and output a message saying “Added” if the value was successfully inserted onto the stack or “Not Added” if the stack is full.

Mark scheme 9(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Calling push() with parameter 15

  • …storing/using return value in selection …

  • …comparing true/false (may be implicit e.g. if

push(15) then ) …
  • …outputting a suitable message if false and if true

e.g.

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

added = push(15)
if added = false then
  print("Not added")
else
  print("Added")
endif

if push(15) then
  print("Added")
else
  print("Not Added")
endif

Guidance

True/False comparisons must be Boolean values and not strings, but allow FT after that.

If push() is called twice BP4 cannot be awarded.

Examiner’s Comments

Some candidates erroneously tried to make a call such as Function Push(15) instead of calling and using/storing the result of Push(15). A number of responses incorrectly used string values “True” / “False” instead of Boolean True / False. Many candidates tried to directly access and use the topStack pointer instead of using the function return value as required in the question.

out of 4

Question 10

9 marks

10(a) 3 marks

The following strings are stored in an array.

“rainbow”“moon”“sun”“stars”“clouds”“tornado”

Explain how a linear search would search the array for the index that stores “clouds”.

Mark scheme 10(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Compare the first element (rainbow) to search item / clouds

  • If it is equal to the search item return index / found

  • If it is not equal move to the next element

  • Repeat until either search item / clouds is equal / or the end of the list has been reached

Guidance

Allow answers by example from the given dataset

Examiner’s Comments

Most candidates scored the majority of the marks available and
demonstrated a clear understanding of a linear search. Many candidates answered by example with values from the given list.

out of 3

10(b) 1 mark

State why a binary search cannot be used in this example.

Mark scheme 10(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for: the data is not in order/sorted

sunstarscloudstornado
moonrainbowValues1 Mark
change
starscloudstornado
moonrainbowsun1 Mark
cloudstornado
moonrainbowstarssunValues1 Mark
change
tornado
cloudsmoonrainbowstarssunValues1 Mark
change
cloudsmoonrainbowstarssuntornado1 Mark

Guidance

Examiner’s Comments

Most candidates correctly identified the requirement for data to be
sorted/ordered for a binary search to work.
‘Organised’ was too vague and was not accepted.

MP2 and MP5 do not have to be explicitly given in full if there is a comment to identify no change occur during the pass.

Award no marks if not an insertion sort.

Examiner’s Comments

Nearly half the candidates achieved full marks and clearly demonstrated the steps involved in an insertion sort for the given data. Some candidates confused insertion sort with either bubble, merge or selection sort, and so scored no marks for not answering the question.

Exemplar 3

[Image redrawn from the original mark scheme by an AI model (Claude Sonnet). It may contain mistakes.]

A candidate's handwritten answer:

(c) Show how an insertion sort will sort the given data into ascending alphabetical order. "rainbow" | "moon" | "sun" | "stars" | "clouds" | "tornado"

rainbow | moon, sun, stars, clouds, tornado moon, rainbow | sun, stars, clouds, tornado moon, rainbow, sun | stars, clouds, tornado [unclear] | clouds, tornado [unclear] | tornado clouds, moon, rainbow, stars, sun, tornado

  • [unclear]

This exemplar
demonstrated the state of the dataset after each pass of the insertion sort. The candidate has separated the sorted and unsorted parts of the list to make the response much clearer.

out of 1

10(c) 5 marks

Show how an insertion sort will sort the given data into ascending alphabetical order.

“rainbow”“moon”“sun”“stars”“clouds”“tornado”
out of 5

Question 11

21 marks

11(a)

A treasure game is being programmed using an object-oriented paradigm.

A class, Treasure, is used to store the treasure objects.

The design for the Treasure class, its attributes and methods is shown here.

class: Treasure
attributes:
private value : integer
private level : string
methods:
new()
function getValue()
function getLevel()

11(a)(i) 5 marks

The constructor method takes a value as an integer, e.g. 100, and a level, e.g. "bronze", as parameters and assigns these to the attributes.

Write pseudocode or program code to declare the class Treasure.

You should define the attributes and constructor method in your answer.

You do not need to write the get methods.

Mark scheme 11(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Defining class Treasure

  • Defining the private attributes value and level

  • Defining a new public procedure…

  • …Taking two parameters (integer and string)

  • Correctly assigning both parameters to the attributes

e.g.

class Treasure

   private value
   private level

   public procedure new(valueP, levelP)
    value = valueP
    level = levelP
   endprocedure
endclass

Guidance

Allow use of this/self or equivalent dependent on language

public procedure
new(value, level)
 this.value =
value
 this.level =
level
endprocedure

Python answers must either use comments to indicate private attributes or use the double underscore private attribute convention to be credited.
self.__level
self.level # private

Examiner’s Comments

This question either tended to be very poorly answered or very well answered. There was a clear division between candidates who were comfortable writing OOP code and class
constructors and those that were not.

Weaker candidates with little OOP experience often confused the class declaration with the instantiation method or offered no response. Many candidates often assigned the parameters to the private attribute values rather than setting the attributes to the parameters being passed in.

Where candidates gave responses in
programming languages and the intent of the response was clear, marks were given. However, sometimes Python programmers did not make it clear (by convention/comment) that class attributes were private.

out of 5

11(a)(ii) 2 marks

The get method getLevel() will return the appropriate attribute.

Write the method getLevel() using either pseudocode or program code.

Mark scheme 11(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • get level method header with no parameter

  • Returning level attribute

e.g.

public function getLevel()
 return level
endfunction

Guidance

Note Python self will appear, but no other parameters

def getLevel(self):

Examiner’s Comments

While there were many good responses it was also noted that a significant number of candidates erroneously tried to send a parameter to a getter() function and then return the same parameter. Some candidates did not return a value or simply tried to print the value. Other errors included writing the getter method as a function call by omitting any indication that a function was being defined.

out of 2

11(a)(iii) 2 marks

Describe the object-oriented programming technique being used in part 9(b)(ii).

Mark scheme 11(a)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Encapsulation

  • Allowing an attribute to only be accessed/changed via a method

Guidance

Examiner’s Comments

Some candidates randomly picked an erroneous OOP term like polymorphism. Those candidates who could correctly identify the use of encapsulation did not always go on to specifically state that this meant access was controlled by a public getter() method.

out of 2

11(b) 5 marks

A text-based computer game allows a user to dig for treasure on an island. The island is designed as a grid with 10 rows and 20 columns to store the treasure. Each square is given an x and y coordinate. Some of the squares in the grid store the name of a treasure object. Each treasure object has a value, e.g. 100 and a level, e.g. "Bronze."

A class, Board, is used to store the 10 row (x coordinate) by 20 column (y coordinate) grid.

The design for the Board class, its attributes and methods is shown here.

class: Board
attributes:
private grid : Array of Treasure
methods:
new()
function getGridItem(x, y)
function setGridItem(x, y, treasureToInsert)

The constructor initialises each space in the grid to a treasure object with value as -1 and level as an empty string.

Complete the following pseudocode for the constructor method.

public procedure new()
 for row = …… to 9
  for column = 0 to ……
   …… [row, column] = new
Treasure(……,"")
  next ……
 next row
endprocedure
Mark scheme 11(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each completed statement

public procedure new()
  for row = 0 to 9
    for column = 0 to 19
     grid[row, column] = new Treasure(-
1,"")
    next column
  next row
endprocedure

Guidance

Examiner’s Comments

Most candidates scored at least the first 2 mark- points for the grid dimensions, but far fewer could construct OOP code requiring the attribute and the relevant default parameter value to be given.

out of 5

11(c) 7 marks

A procedure, guessGrid():

  • takes a Board object as a parameter
  • accepts the row (x) and column (y) coordinates from the user
  • outputs "No treasure" if there is no treasure found at the coordinate (level is an empty string) if there is treasure at that coordinate, it outputs the level and the value of the treasure in an appropriate
  • message.

Write the procedure guessGrid() using either pseudocode or program code.

Mark scheme 11(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 7

  • Procedure declaration taking parameter

  • Taking two inputs for row and column from the user

  • Accessing item at grid position…

  • …using correct get methods getGridItem

  • Checking (treasure) object’s level/value…

  • …using correct get method getLevel getValue

  • …outputting "No treasure" if empty

  • …otherwise outputting value and level

e.g.

procedure guessGrid(gameboard)
   rCoord = input("Enter R coordinate")
   cCoord = input("Enter C coordinate")
 treasureItem =
gameBoard.getGridItem(rCoord, cCoord)
 if treasureItem.getLevel() = "" then
   print("No treasure")
 else
   print("This treasure is level ",
treasureItem.getLevel(), " with value ",
treasureItem.getValue())
endprocedure

Guidance

Note candidates may attempt to access private

attributes directly gameboard.grid(x,y) for example, instead of gameboard.getGridItem(x, y).

Credit cannot be given for the dependent second mark using appropriate get method if they do this, but FT marks can be awarded for later points if a reasonable attempt has been made.

Examiner’s Comments

Many candidate responses gave very little beyond the procedure declaration and taking in the x and y coordinates as inputs, thus scoring 2 marks at most. There was less successful
understanding of how to use the get() methods provided in the scenario to access the data. This is an area of the
specification that candidates require extensive practical experience of to be able to fluently answer questions like this in examination conditions.

Many candidates tried to used grid[x,y] by inserting the coordinates into the parameter values and did not identify it as an instance of an object that needed its attributes to be accessed via the appropriate getter methods. Those candidates who tried to access the attributes directly without the appropriate getter methods did achieve some further marks with

follow through marks.

Competent coders often gave responses worthy of full marks within just a few lines of code.

Exemplar 3

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

def guessGrid(board):
    [unclear]
    x = int(input("enter x"))
    y = int(input("enter y"))
    place = board.getGridItem(x, y)
    if place.getLoad() == 0:
        print("No treasure")
    else:
        print("Treasure found! [unclear] at [unclear] place.get")
        print("it is a " + place.getLoad())

This response clearly shows a logical and well- structured algorithm that uses the appropriate get() methods to access the relevant attributes of the passed parameter object. Candidates who are fluent in the use of OOP can present elegant and concise solutions.

out of 7

Question 12

2 marks

12 2 marks

Give two reasons why reusable program components are used in programs.

1

2

Mark scheme 12

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 2:

  • One piece of code can be used many times / in multiple places / makes code more efficient

  • No need to write the same code multiple times

  • Takes less time to plan/design/code the program

  • Easier error detection as fix once and it corrects in each place / less likely to have errors as code is not written multiple times

  • Makes it easier to maintain the program

Guidance

Examiner’s Comments

Many less successful responses gave vague generalities such as ‘saves time’ or ‘more efficient’ without specifying why or how. Points given must be qualified in some way at A Level. For example, ‘saves development time as pre- written routines are available’.

Pre-written or pre-tested, and saving development time due to already being written, were the most popular answers.

out of 2

Question 13

8 marks

13(a) 3 marks

A recursive pseudocode function, recursiveAlgorithm(), is shown.

01   function recursiveAlgorithm(value)
02     if value <= 0 then
03       return 1
04     elseif value MOD 2 = 0 then
05       return value + recursiveAlgorithm(value – 3)
06     else
07       return value + recursiveAlgorithm(value – 1)
08     endif
09   endfunction

Describe the key features of a recursive algorithm.

You may refer to the function, recursiveAlgorithm() in your answer.

Mark scheme 13(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 3

  • The function calls itself….

  • …..such as line 05 / 07

  • Each recursive call will create a new copy of the values in the function….

  • ….and add all of the values of the copy the call is being made from to a stack

  • There is a base case / condition that stops the recursive calls…

  • …condition in line 02

  • There may be more than one base case

Guidance

Allow answers in context as long as they are clear what the features are.

Examiner’s Comments

Weaker responses were limited to one or two points for ‘calls itself’ with example such as ‘line 05’. Fewer candidates went on to identify the requirement for a base case. A variety of terminology was used for the base case such as terminating case and stopping case. If candidates were clearly referring to the case where the recursive calls stopped, and the recursion started to unwind, the mark was given.

out of 3

13(b) 5 marks

Trace the recursive function, recursiveAlgorithm(), and give the final return value when called with recursiveAlgorithm(10). You may choose to use the table below to give your answer.

Function callvaluereturn

Final return value ……

Mark scheme 13(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for final return value 29 (award in working or answer space) 1 mark each for working

  • First call with 10 and second call with 7

  • Remainder of calls 6, 3, 2

  • Final call value -1

  • Adding/showing return values (1 + 2 + 3 + 6 + 7 + 10)

e.g.

Function callvaluereturn
recursiveAlgorithm(10)1029
recursiveAlgorithm(7)719
recursiveAlgorithm(6)612
recursiveAlgorithm(3)36
recursiveAlgorithm(2)23
recursiveAlgorithm(–1)–11

Guidance

The table is given as guidance, but actual process may be presented in different ways.

Examiner’s Comments

While many candidates continue to find recursion a challenging topic there were many who encouragingly achieved full marks. Weaker candidates traced the initial sequence of calls but found it harder to identify the last call to

recursiveAlgorithm(
  • -1) that triggered the base case and then found it harder again to calculate the unwind sequence.
out of 5

Question 14

6 marks

14 6 marks

Octal is a base 8 number system.

To convert a denary number to base 8:

  • the denary value is divided by 8 and the remainder is stored
  • the integer value after division is divided by 8 repeatedly until 0 is reached
  • the remainders are then displayed in reverse order.

Example 1:

Denary 38
38 / 8 = 4 remainder 6 6 4 / 8 = 0 remainder 4 4 Octal = 46
Example 2:
Denary 57
57 / 8 = 7 remainder 1 1 7 / 8 = 0 remainder 7 7 Octal = 71

Write an algorithm to:

  • take a denary value as input from the user
  • convert the number to octal
  • output the octal value.

You do not need to validate the input from the user.

Write your algorithm using pseudocode or program code.

Mark scheme 14

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 6

  • Taking number as input

  • Calculating remainder after division by 8

  • Calculating integer after division by 8

  • Correct loop until 0 is reached (or equivalent method)

  • Concatenating each remainder / storing each remainder in an array/list

  • Outputting the correct result

e.g. pseudocode

number = input("Enter a number")

endResult = ""

while number != 0
  remainder = number MOD 8
  number = number DIV 8
  endResult = str(remainder) + str(endResult)
endwhile
print endResult

Guidance

Note candidates can reverse the string before output if they don’t

concatenate in the order given in the example. E.g.

endResult =
str(endResult)
+ str(remainder)

The final markpoint can only be awarded where the correct output will be produced by the algorithm.

Examiner’s Comments

In general, there was a very poor standard of pseudocode algorithms from less successful responses. This demonstrated poor programming and limited problem-solving ability.

While there was no requirement to define a function the strongest candidates often did so, but then some forgot the requirement specified in the question for user input, rather than just presenting a
parameterised function in isolation.

There were several common errors that were observed. A few candidates performed the octal conversion for just two digits rather than generalising the solution for a denary number of any length. Many candidates simply used ‘/’ for division without specifying integer division through /, DIV or floor functions. Many candidates did not assign the result of a calculation to a variable for later use, presenting lines of code

such as ‘denaryNum MOD 8’ which was not given marks. The order required for appending the remainder was frequently incorrect in many of the solutions that were presented, although some candidates did reverse the string at the end of the process if they did

‘outString +=

remainder’ style solutions, which was acceptable.

Most candidates achieved at least 1 mark for taking user input, and then the majority also used either modulus to calculate the remainder or integer division to calculate the value for the next iteration. Only the strongest candidates scored 5 or 6 marks.

Exemplar 1

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

Value = Input("entry a number")
Output = ""
while Value != 0
    Output = Str(Value MOD 8) + Output
    Value = Value DIV 8
endwhile
if Output == "" then
    Output = 0
endif
Print(Output)

This candidate response is not language specific but the logic and the operations used are clear. It shows clear logical structure with appropriate indentation of logical blocks. It was given full marks.

out of 6

Question 15

16 marks

15(a) 9 marks

A program designer needs to decide on an algorithm to use from a choice of three. The table shows the worst-case Big O complexities for each algorithm.

AlgorithmTime ComplexitySpace Complexity
1LinearExponential
2ExponentialConstant
3LogarithmicLogarithmic

The program will be used to analyse data that can range from 2 items to 2 billion items.

Compare the use of all three algorithms and suggest which the programmer should use.

You should include the following in your answer:

  • the meaning of constant, logarithmic, linear and exponential complexity
  • how well each algorithm scales as the amount of data increases
  • which algorithm is the most suitable for the given task.
Mark scheme 15(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level
(7–8 marks)
The candidate demonstrates a thorough knowledge and

understanding of Big O; the material is generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided. Evidence/examples will be explicitly relevant to the explanation.
There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level
(4–6 marks)
The candidate demonstrates reasonable knowledge and understanding of Big O; the material is generally accurate but at times underdeveloped.
The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate provides a reasonable discussion, the majority of which is focused. Evaluative comments are, for the most part appropriate, although one or two opportunities for development are missed.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence.

Mark Band 1 – Low Level
(1–3 marks)
The candidate demonstrates a basic knowledge of Big O with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and understanding to the context provided.
The candidate provides a limited discussion which is narrow in focus. Judgements if made are weak and unsubstantiated. The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 mark
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding Indicative content

  • Big O measures the number of steps and memory usage change according to the data as the amount of data being processed increases
  • Linear - grows in proportion to amount of data
  • Exponential – the rate of increase is at the rate kn as n increases
  • Constant - it does not change
  • Logarithmic – means the rate of increase gets smaller as the amount of data increases time / time increases at a rate of logkn as n increases.

AO2: Application

  • Algorithm 1 – The time taken increases as the data set grows. The space taken also significantly increases. This algorithm is not memory efficient.
  • Algorithm 2 – The time increases significantly and therefore this algorithm is not time efficient. The space will never change which means the amount of memory will not change as the data set grows.
  • Algorithm 3 – The time will grow less

fast as the data set grows relative to the other algorithms. The space required will also increase, but not
insurmountably. This is therefore an efficient algorithm with large data sets compared to algorithm 1 and 2 overall.

AO3: Evaluation

  • Number of elements is unknown. Exponential is least appropriate because this could increase significantly and be unmanageable.
  • Constant is the most ideal as the time will not increase.
  • Algorithm 3 is more suitable because it has a logarithmic time complexity, so it increases less quickly than the other algorithms. It will be reasonable with a small amount (2 items) of data, but then when very large amounts (2 billion items) are needed it will not be significantly more.

Examiner’s Comments

Several candidates confused logarithmic and exponential growth rates, and a significant number of candidates thought that

exponential complexity was the polynomial function O(n2) rather than O(2n). Many candidates also defined terms such as exponential complexity as ‘where it grows
exponentially’, such circular definitions were not given marks.

Level 1 responses identified some
characteristics of Big O for constant, logarithmic, linear and exponential complexity with some occasional errors or inconsistencies.

Level 2 responses gave reasonable descriptions of both time and space complexity alongside accurate definitions for the complexity terms with an identification of algorithm 3 as being the best overall choice.

Level 3 responses had far more evaluative AO3 analysis but were few and far between. In this scenario candidates identified that it depended on the value of n, as if n was very small, exponential time growth was not an issue, so algorithm 2 might be preferential, but as n could grow to 2 billion this would be intractable, so algorithm 3 was chosen as the most practical. The data set in question had 2 billion items at most so log22,000,000,000 = 30 meant space overheads in algorithm 3 were manageable with modern storage capacities.

Exemplar 2

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

A candidate's handwritten answer:

Order is used to evaluate the complexity of an algo in respect to how its performance changes with a change to the size of input. This means be measuring how much longer it takes to complete, how much additional load is placed on components such as memory.

Linear complexity means that the time taken is [linear] to the size of the input, and will grow at a linear rate as input size increases.

Constant complexity means that no matter the size of input, the time (load) will always be the same regardless of the data being processed.

Exponential complexity grows very quickly as inf increases, whilst logarithmic increases, though at a

This response clearly demonstrates that a high scoring Level 3 response is possible within the space provided. The second page of the response shows clear AO3 evaluation between the merits of the three different algorithms and the scenario.

out of 9

15(b)

A programmer needs to use a merge sort in one part of the problem to sort items in ascending order.

15(b)(i) 5 marks

Describe how a merge sort works.

Mark scheme 15(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 5

  • The data list is split into two lists

  • These sublists continue to be (recursively) split…

  • …until each sublist is one item

  • The first element in two different sublists is compared…

  • …the smaller item is then selected…

  • …and written to a new list

  • …until both sublists fully merged

  • Repeated until all sorted sublists are recombined

Guidance

Allow array/list as equivalent

Examiner’s Comments

Many candidates were not precise in describing how the initial data set was repeatedly halved and did not explain how the data set was actually broken down into individual items. Very few candidates could accurately describe how the merge phase of a

merge sort combines two separate ordered lists together, and frequently this was omitted altogether. A number of candidates continued to demonstrate the misconception that data is sorted within sub-lists, rather than by the actual merging of two separate ordered lists together.

[An examiner's marking symbol, not shown here.]

Misconception

Many candidates continue to think that a merge sort performs sorting of data within lists.

Merge sort performs the sorting part of the operation when it merges together two separate sub- lists that are already in a sorted order. This is done with the use of a pointer to each of the two sub-lists that acts as a placeholder. The two positions in the separate lists are compared, and the smaller item is added to the new sorted list and the pointer is incremented. The merging process then repeats until the sub-lists have been completely merged.

out of 5

15(b)(ii) 2 marks

Give one benefit and one drawback of the programmer using a merge sort instead of a bubble sort.

Benefit

Drawback

Mark scheme 15(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for benefit
e.g.

  • More efficient time complexity (for large data sets) / takes fewer steps to sort the data

  • Time complexity O(n log n), rather than O(n2)

  • Uses divide and conquer

  • Can apply concurrent processing to reduce sorting time

1 mark for drawback
e.g.

  • More difficult to implement / needs more complex code

  • Less efficient space complexity / uses more memory with more data items

  • Space complexity of O(n)/linear, rather than O(1) / constant

  • Merge sort is always O(nlog2n) whereas the best case for bubble sort is O(n)

Guidance

Examiner’s Comments

Most candidates recognised that merge sort is typically quicker than bubble sort, but there were some unqualified answers. Clear responses were phrased in terms of Big O complexities or the numbers of data items to

be sortonses were phrased in terms of Big O complexities or the numbers of

out of 2

Question 16

24 marks

16(a)

A tree is one example of a data structure.

16(a)(i) 2 marks

Give two characteristics of a tree data structure.

1

2

Mark scheme 16(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 2

  • It is a hierarchical structure / not directed

  • Data is stored in nodes

  • Nodes are linked by branches/edges

  • It has a root node

  • Each node has zero or more nodes 'beneath' it / nodes can link to child nodes

  • It has leaf nodes / nodes without any lower nodes are leaf nodes

  • It has no cycles/loops (distinguishing it from a graph)

Guidance

Examiner’s Comments

This question was generally well answered by most candidates with the most common answers including different types of nodes such as root, child and leaf nodes.

Some candidates used vague terminology or used terminology more commonly associated with graphs such as vertices instead of nodes, or edges instead of branches. Imprecise language such as undirected/non-directed was used whereas it would have been clearer to have indicated that trees are hierarchical structures that are rooted. Some candidates erroneously confused binary trees with general trees stating that nodes could only have a maximum of two child nodes, as the tree in this question was not specifically limited to the special case of a binary tree.

out of 2

16(a)(ii) 4 marks

The following data is entered into a binary search tree.

22 13 5 36 55 14 8
Draw the binary search tree when the given data is entered in the order given.

Mark scheme 16(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Root node 22 at the start

  • 13 and 14 in correct order

  • 5 and 8 in correct order

  • 36 and 55 in correct order

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    22["22"]
    22 ---|left| 13["13"]
    22 ---|right| 36["36"]
    13 ---|left| 5["5"]
    13 ---|right| 14["14"]
    36 ---|right| 55["55"]
    5 ---|right| 8["8"]

Guidance

Do not allow nodes to be drawn downwards.

Examiner’s Comments

Most candidates gained some marks, with many gaining full marks. Occasionally the left/right ordering of child nodes was unclear, so marks could not be given in such instances.

out of 4

16(a)(iii) 2 marks

Describe how a leaf node is deleted from a binary search tree.

Mark scheme 16(a)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Search/traverse tree until the required node is found

  • Set the parent node pointer to the leaf node to null

  • Add the deleted node to the free storage list / leave for garbage clear up

Guidance

Examiner’s Comments

This question was generally less successfully answered by many candidates. There was considerable vagueness in some responses such as ‘finding the end node and removing it’. This left questions such as ‘Which end node?’, ‘Removed how?’ for the examiner to infer, so were too vague to gain marks.

When candidates identified the need to locate the leaf node, most omitted the need for the parent node pointer to be set to null to break the link. Very few candidates indicated that a deleted node would then be added to a free list or that the memory freed could be retrieved via garbage collection.

out of 2

16(a)(iv) 4 marks

Describe how a binary search tree can be searched for a value.

Mark scheme 16(a)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 4

  • Check if the root node is equal to search value and if so….

  • …return/output/report found

  • If value is less than root node take left subtree

  • If value is greater than root node take right subtree

  • Repeat process with the subtree…

  • …until search value is found

  • …until no more branches can be travelled.

Guidance

Examiner’s Comments

This question was generally well answered by many candidates who appreciated that a Binary Search Tree (BST) could be efficiently searched because it is ordered, rather than traversed.

Weaker candidate often confused the search of a BST structure with traversal algorithms such as breadth first or depth first traversals.

out of 4

16(a)(v) 4 marks

Identify the order that the nodes will be visited in a depth-first (post-order) traversal of this binary search tree.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    H["H"] ---|left| C["C"]
    H ---|right| P["P"]
    C ---|left| A["A"]
    C ---|right| F["F"]
    P ---|left| L["L"]
    P ---|right| T["T"]
Mark scheme 16(a)(v)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • Visiting A first…

  • …Then visiting F, C…

  • …Then visiting L, T, P…

  • …Visiting H last

Solution: A, F,C, L,T,P, H

Guidance

Examiner’s Comments

Some candidates confused Depth First Search with other traversal algorithms, most commonly Breadth First Search, but this question was generally answered well by most candidates. Another common mistake was to output the nodes in the order in which they were first encountered rather than the order in which they would be visited/output.

out of 4

16(a)(vi) 2 marks

Explain how backtracking is used in depth-first (post-order) traversals.

Mark scheme 16(a)(vi)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 2

  • When a leaf node is reached…

  • …the traversal backtracks to the leaf’s parent node

  • …backtracks to last node with unvisited children

Guidance

Candidates may use an example from the tree in 1a(v) to illustrate their response.

If an answer gives implementational detail of how a stack is used, map to the bullet points given.

Examiner’s Comments

Some candidates described the term ‘backtracking’ in general, so did not answer the question, which required a response in the context of a depth first tree traversal. Many candidates thought that backtracking always began at the leftmost node, which is not true, it starts when a leaf node is reached.
However, a pleasing number of candidates did identify the first example of backtracking in the

given tree, from leaf A to parent node C.

out of 2

16(b) 6 marks

A graph is a type of data structure.

An example graph is shown in Fig. 1.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

graph TD
    A ---|2| C
    A ---|5| B
    A ---|10| D
    B ---|2| E
    C ---|8| D
    D ---|4| G
    E ---|12| G
    E ---|8| F
    F ---|1| G

Fig. 1

Show how Dijkstra’s algorithm can be used on the graph shown in Fig. 1 to find the shortest path from start node A to end node G.

You must state the nodes on the final path and the distance of this path. Show your working.

You may use the table below to give your answer.

NodeDistance travelledPrevious node

Final path: ……

Distance: ……

out of 6

Question 17

14 marks

17(a) 2 marks

A program stores data in a linked list.

The current contents of the linked list are shown in Fig. 3, along with the linked list pointers.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

locationdatapointer
0"blue"6
1"red"0
2"green"8
3"orange"NULL
45
57
6"grey"2
79
8"purple"3
9NULL

headPointer: 1 freeListPointer: 4

Fig. 3

State the purpose of headPointer and freeListPointer in the linked list shown in Fig. 3.

headPointer
freeListPointer
Mark scheme 17(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each

  • headPointer: To indicate the first element in the list

  • freeListPointer: To indicate the next index to store data in (the freeList)

Guidance

Examiner’s Comments

While many candidates did gain full marks, a noticeable number of candidates struggled with the use of technical language in this question. Where a candidate’s intention or meaning was clear, for example, ‘headPointer is the first item’ or ‘freeListPointer is the first free space’, marks were given. Some candidates did not show an understanding that these pointers represented the start of two separate linked lists within the static array structure.

out of 2

17(b) 1 mark

State the meaning of the pointers with the value NULL in the linked list shown in Fig. 3.

Mark scheme 17(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

It doesn't point to another node
Indicates the end of the linked list

Guidance

Examiner’s Comments

This question was generally well answered, with many candidates gaining marks. A generic ‘no assigned value’ was not given marks, as the response had to be answered in the context of the linked list, so end of list/not pointing to another node was required, rather than stating pointing to nothing.

out of 1

17(c) 2 marks

A procedure outputs the data in the linked list shown in Fig. 3 from the first item in the list, to the last item.

Give the output from the procedure.

Mark scheme 17(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

  • first output red…

  • …remainder of list correct

e.g.
red blue grey green purple orange

Guidance

Examiner’s Comments

Again, this question was generally well answered by most candidates. The most common erroneous answer was ‘Blue’ as it was the first item in Figure 3 given at index 0. This was invariably given as a response when candidates did not know what the function of the
headPointer was.

out of 2

17(d) 4 marks

A new item needs to be added to the linked list.

Describe how a new item is added to a linked list.

Mark scheme 17(d)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 4

Check space available in the free list

  • Check to make sure freeListPointer is not Null

Add new data item to first free space in free list

  • Insert new data item at index freeListPointer (index 4)

Append e.g.

  • Traverse to / locate the end of the list (index 3 ‘orange’)

  • Set the pointer of the last item in the linked list to freeListPointer (pointer at index 3 ‘orange’ changes from Null to 4)…

  • … update freeListPointer to the location that new data item pointer is pointing to at present. (freeListPointer changes from 4 to 5)

  • … update pointer from new data item to Null (index 4 pointer changes from 5 to Null)

Prepend e.g.

  • Update freeListPointer to point to the location that the pointer from the first item in the free list is pointing to (freeListPointer changes from 4 to 5)

  • … Update pointer from new data item to headPointer (index 4 pointer changes from 5 to 1)

  • … Update headPointer to the index of new data item (headPointer changes from 1 to 4)

Guidance

Note descriptions could be for either appending an item to the end of the current list or prepending it to the start. There are different ways to achieve this.

Allow answers that illustrate solutions by example from the table in Fig 3 at the start of the question.

Reponses must refer to the relevant pointers or give clear
exemplifications.

Examiner’s Comments

More successful responses gave good clear examples to illustrate a potential sequence of operations to describe the process, and many therefore achieved 3 or 4 marks. For example ‘new item added to location 4 indicated by

FreeListPointer and

its pointer set to Null; Existing list searched from headPointer to its end at Orange at index 3, and its pointer updated to the new last item in the list at index 4.’

Some candidates lacked appreciation that this was a static record structure in this scenario, so locations from the free list had to be used. Many candidates were unclear as to how the end of the current linked list was found, and just gave answers from that point onward without saying how it was found by traversing to the end of the existing list. There

were relatively few prepend type solutions, but they were accepted as valid where seen.

out of 4

17(e) 5 marks

The function findNode will search the linked list and return either the position of the node that contains the data item, or -1 if the data item is not found.

The data held in a node at location x can be accessed with linkedList[x].data. The pointer of the node at location x can be accessed with linkedList[x].pointer.

For example, using the linked list shown in Fig. 3:
linkedList[2].data returns green.
linkedList[2].pointer returns 8.

Complete the function, using pseudocode or program code.

function findNode(toFind, headPointer, linkedList)

  currentNode = ……

  while(currentNode != ……)

    if linkedList[currentNode]. …… == toFind then

      return currentNode

    else

      currentNode = linkedList[……].pointer

    endif

endwhile

return ……

endfunction
Mark scheme 17(e)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each statement

function findNode(toFind, headPointer,
linkedList)
  currentNode = headPointer
  while(currentNode != NULL)
    if linkedList[currentNode].data ==
toFind then
      return currentNode
    else
      currentNode =
linkedList[currentNode].pointer
    endif
  endwhile
  return -1
endfunction

Guidance

Ignore case of identifiers in pseudocode

Only penalise excessive spaces within identifier names if obvious.

Examiner’s Comments

This question required exact answers only. Many candidates gained some marks, and there was a good distribution of marks. More successful programmers tended to get most of the marks available.

out of 5

Question 18

3 marks

18

Layla writes a pseudocode algorithm to:

  • input 20 positive numbers into a 0-indexed 1-dimensional array
  • output the average (mean) number as a decimal
  • output the smallest number
  • output the largest number.

The pseudocode algorithm is shown. It contains various errors.

01 total = 1
02 smallest = 9999
03 largest = -1
04 for x = 0 to 21
05   dataArray[x] = input("Enter a number")
06   total = total + dataArray[x]
07   if dataArray[x] < largest then
08     largest = dataArray[x]
09   endif
10   if dataArray[x] < smallest then
11     smallest = dataArray[x]
12   endif
13 next x
14 print("Average = " + total * 20)
15 print("Smallest = " + smallest)
16 print("Largest = " + largest)

dataArray is defined as a local variable within the main program.

18(i) 1 mark

State what is meant by a ‘local variable’.

Mark scheme 18(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

it can only be accessed within the subroutine/block in which it is declared

Guidance

Examiner’s Comments

Few candidates were able to clearly define the term 'local variable'. The concept of scope of variable s appeared to be poorly understood, with few able to define that a local variable’s scope was that of the
function/procedure in which it was declared.

out of 1

18(ii) 2 marks

Give one benefit and one drawback of declaring dataArray as a local variable in the main program.

Benefit

Drawback

Mark scheme 18(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for benefit
e.g.

  • Increases data integrity

  • More efficient memory usage

  • Stops other subroutines accidently altering variable

1 mark for drawback
e.g.

  • Cannot be accessed directly by other subroutines

  • It has to be passed into a subroutine as a parameter

Guidance

Examiner’s Comments

Some candidates confused the terms local variable and global variable and gave de finitions the wrong way round. A significant number of responses demonstrated conceptual misconceptions. The contents of dataArray could be used in other parts of the program if it was passed as a

parameter to a
function/procedure, but could not be referenced directly. Responses such as giving ‘can’t be used anywhere else in the program’ as a
disadvantage were, therefore, incorrect.

out of 2

Question 19

10 marks

19(a)

A program stores data in a 1-dimensional array.

The program needs to search the array for a number that is input by the user.

19(a)(i) 5 marks

Describe how a linear search will search the data in the array for a number that has been input.

Mark scheme 19(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • Start with the first element

  • Compare it to the number input

  • If it is equal, return the index / True

  • If not equal, move to the next element and repeat

  • Repeat until it is found, or the end of the array is reached

  • If found, return the index where the data was found

  • If the end of the list was reached, return -1 / False / “not found” message

Guidance

Examiner’s Comments

A pleasingly high number of candidates
demonstrated a clear understanding of how a linear search operated and used clear and accurate language. More candidates were clearer in the way that they articulated the steps of the search than in previous series. However, there were still a number of candidates who gave vague responses such as ‘check each valu e until the value input is found’ that did not articulate the required steps. Some candidates gave advantages or
disadvantages of using a linear search but such responses did not answer the question.

out of 5

19(a)(ii) 1 mark

State why you would use a linear search rather than a binary search.

Mark scheme 19(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • If the data is not in any order / binary search requires the data to be in order

  • When the number of items to search is small

Guidance

Examiner’s Comments

Many candidates identified the fact that a linear search can operate on an unordered array whereas a binary search cannot. Some candidates alternatively cited the fact that a linear search could be used when the number of items to search was small, which was valid when qualified by the nu mber of items.

out of 1

19(b) 4 marks

Describe how an array can be used to store and access data in a stack data structure.

Mark scheme 19(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 4

  • (Stack) Pointer points to the last element added to the stack / top of the stack

  • New data is added to the pointer position / pointer+1…

  • …check for overflow condition

  • …pointer is then incremented

  • Data is removed from pointer/pointer-1 position…

  • …check for underflow condition

  • …pointer is then decremented

  • Elements can be accessed through Push() and Pop() methods that are implemented

Guidance

Note: Answers must relate to an array
implementation which means that a stack pointer must be implemented.

Examiner’s Comments

Candidates need to be mindful of the fact that an array is a static data structure with a predetermined size. This meant that responses that explained how lists could be used to append and remove items were not given marks. This is an area where candidates who only have
programming experience of using lists in Python often struggle.

Implementing a stack in an array requires a stack pointer. Those candidates who appreciated this and who clearly had practical experience of modelling push()/pop() operations on a stack were able to articulate how the stack would access array locations at the stack pointer.

Exemplar 3

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

A candidate's handwritten answer:

you can create a one dimensional array and have pointers enter values putting to the first at the bottom and then another putting to the at the top. of an item is popped the item at the index position of the top is deleted and the pointer's value decreases by one. if you want to enter another item you append to the list to the "position of the top then you should check if top pointer = bottom position, so stack is empty, and if (top > n) is greater than the length of the array to see if there is full.

This exemplar was one of the few responses to show a clear insight as to how an array can be used to store and access a stack.

It makes it clear that a stack pointer is required and goes on to explain how the stack pointer is manipulated when push()/pop() operations are performed.

[An examiner's marking symbol, not shown here.]

Misconception

Many candidates were not clear about the difference between an array and a list:

  • An array is a static structure whose size cannot be changed.
  • Lists are dynamic and support items being removed or appended.
out of 4

Question 20

2 marks

20(i) 1 mark

The array numbers contains 356 numbers to be sorted by the bubble sort algorithm.

State the maximum number of passes a bubble sort would need to complete to sort 356 numbers into order.

Mark scheme 20(i)

355

Guidance

Examiner’s Comments

Many candidates did not appreciate that a bubble sort will require a maximum of n -1 passes in the worst case since the first item in the list will be in position after that number of passes and so would not require an additional pass. The most common incorrect responses were 356, and 3562 which confused the worst case time complexity O(n2) with the number of passes.

20(ii) 1 mark

State the name of one other sorting algorithm.

Mark scheme 20(ii)

Insertion sort

Guidance

Accept any valid sorting algorithm
e.g. Merge sort, Quick sort

Examiner’s Comments

Nearly all candidates could identify an additional sorting algorithm with the most common response being ‘Insertion sort’.

Question 21

10 marks

21(a) 6 marks

A function, toBinary(), is needed to calculate the binary value of a denary integer between 0 and 255.

toBinary() needs to:

  • take an integer value as a parameter
  • divide the number by 2 repeatedly, storing a 1 if it has a remainder and a 0 if it doesn’t
  • combine the remainder values (first to last running right to left) to create the binary number
  • return the binary number.

For example, to convert 25 to a binary number the steps are as follows:

25 / 2 = 12 remainder 1
12 / 2 = 6 remainder 0
6 / 2 = 3 remainder 0
3 / 2 = 1 remainder 1
1 / 2 = 0 remainder 1

return value = 11001

Write the function toBinary().

You should write your function using pseudocode or program code.

Mark scheme 21(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 6

  • function header taking parameter

  • looping appropriately e.g. until value is 0

  • dividing by 2 and finding remainder e.g. MOD

  • adding 1 or 0 correctly

  • …appending to a value to be returned / final string reversed

  • reducing value to use within loop

  • returning calculated value

e.g.

function toBinary(denary)
  binaryValue=""
  while denary > 0
    temp = denary MOD 2
    if temp == 1 then
      binaryValue = "1" + binaryValue
    else
      binaryValue = "0" + binaryValue
    endif
  denary = denary DIV 2
  endwhile
  return binaryValue
endfunction

Guidance

Award a recursive algorithm as equivalent

Examiner’s Comments

Very few candidates were able to produce a working function, but many gained some marks.

Some candidates had little idea of the concept of a function and struggled to define one. Many omitted the definition statement or omitted the required parameter and then asked for user input instead.

The standard of pseudocode/code was quite weak. Indentation of constructs was often missing or hard to follow. Mid-range marks were achieved when candidates effectively utilised MOD to determine if the remainder on division by two was odd or even, and then using DIV to find the next term in the sequence.

More successful responses demonstrated an ability to problem solve, think logically, and present clear working functions.

out of 6

21(b) 4 marks

The main program:

  • asks the user to enter a denary number between 1 and 255
  • checks that the input is valid between 1 and 255
  • If valid call the function toBinary() and pass the input as a parameter
  • outputs the return value
  • If not valid, repeatedly asks the user to input a number until the number is valid.

Write the algorithm for the main program.

You should write your algorithm using pseudocode or program code.

Mark scheme 21(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 4

  • taking value as input

  • looping until valid between 1 and 255

  • calling function with correct parameter

  • outputting return value

denary = -1
while denary < 1 or denary > 255
  denary = input("Enter denary value between
1 and 255")
endwhile
print(toBinary(denary))

Guidance

Allow other checks for a valid number. For example

denary.isInteger ==
False

Examiner’s Comments

Candidates found Question 4 (b) easier to approach than Question 4 (a). Most could write pseudocode to accept a user input. When validating the input to be a value between 1 and 255, there was incorrect use of relational operators with off -by-one errors on occasion. There was also incorrect use of logical operators where or was used instead of and, and vice-versa. When candidates called

toBinary(inputVal),

the result was not always stored for later use.

[An examiner's marking symbol, not shown here.]

Assessment for learning

When preparing candidates for the examination, they will benefit from a wide range of programming experience.

Questions such as 4 (a) and 4 (b) present an ideal opportunity for developing coded solutions to test and discuss before looking at how the algorithms could be presented as pseudocode.

out of 4

Question 22

8 marks

22(a)

Layla writes a pseudocode algorithm to:

  • input 20 positive numbers into a 0-indexed 1-dimensional array
  • output the average (mean) number as a decimal
  • output the smallest number
  • output the largest number.

The pseudocode algorithm is shown. It contains various errors.

01 total = 1
02 smallest = 9999
03 largest = -1
04 for x = 0 to 21
05   dataArray[x] = input("Enter a number")
06   total = total + dataArray[x]
07   if dataArray[x] < largest then
08     largest = dataArray[x]
09   endif
10   if dataArray[x] < smallest then
11     smallest = dataArray[x]
12   endif
13 next x
14 print("Average = " + total * 20)
15 print("Smallest = " + smallest)
16 print("Largest = " + largest)

22(a)(i) 1 mark

Identify the construct used on lines 01 to 03 in the algorithm.

Mark scheme 22(a)(i)

sequence

Guidance

Examiner’s Comments

Nearly all candidates correctly identified ‘sequence’ as the correct construct.

22(a)(ii) 1 mark

Identify the construct used on lines 10 to 12 in the algorithm.

Mark scheme 22(a)(ii)

selection / branching

Guidance

Examiner’s Comments

Nearly all candidates correctly identified ‘selection’ as the correct construct.

22(b) 2 marks

Identify two variables used in this algorithm.

1

2

Mark scheme 22(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark each to max 2

  • total

  • smallest

  • largest

  • x

  • dataArray

Guidance

Examiner’s Comments

Most candidates correctly identified two variables from the given code.

out of 2

22(c) 4 marks

The algorithm that Layla has written has many errors.

Identify the line number of four different errors and write the corrected line of code.

Error 1 line number ……

Error 1 correction

Error 2 line number ……

Error 2 correction

Error 3 line number ……

Error 3 correction

Error 4 line number ……

Error 4 correction

Mark scheme 22(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each line and correction

  • Line 01

total = 0
  • Line 02

• smallest = dataArray[0]
  • Line 04 for x = 0 to 19 (accept 20)

  • Line 07

if dataArray[x] > largest then
  • Line 14

print("Average = " + total / 20)

Guidance

Do not award a mark for the line number alone without correction.

Examiner’s Comments

Most candidates were given some marks, but fewer achieved full marks.

The context of the question indicated that the numbers input were positive integers, but candidates did not always appreciate this.

out of 4

Question 23

13 marks

23(a) 4 marks

A program uses a bubble sort to sort data into ascending numerical order.

The data is stored in a 0-indexed 1-dimensional array.

Show each stage of a bubble sort to sort this data into ascending numerical order:

153927

You should clearly show and label each pass in your answer.

Mark scheme 23(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • 1st swap of 5 and 3

  • Remainder of first pass

  • Pass 2

  • Pass 3

153927
135927
135297
135279
132579

End of pass 1

123579

End of pass 2

End of pass 3

Guidance

Candidates do not need to show each swap, so if the candidate has clearly shown the end of pass 1, they have met the first two marking points.

Marks can be awarded for correctly showing the results of each pass.

Examiner’s Comments

Most candidates clearly showed the steps that would take place in a bubble sort for the date given, with most achieving full marks. Some candidates did not

explicitly label each pass as required in the question, but marks were given where the passes could be implied.

Few candidates described the principles of a bubble sort instead of applying it to the data given.

out of 4

23(b)

A programmer has partially developed a bubble sort algorithm in pseudocode.

This will partially sort an array of numbers called numbers that is passed as a parameter.

01 procedure bubbleSort(numbers : byRef)
02   flag = true
03   for x = 0 to numbers.length – 1
04     if numbers[x] > numbers[x + 1] then
05       holdValue = numbers[x]
06       numbers[x] = numbers[x + 1]
07       numbers[x + 1] = holdValue
08       flag = false
09     endif
10   next x
11 endprocedure

23(b)(i) 3 marks

Explain why the procedure bubbleSort accepts the array numbers by reference and not by value.

Mark scheme 23(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • by reference will reorder the contents of the array

  • …so the new order can be accessed by the main program / so will be saved when the procedure ends

  • by value will change the array only in this procedure

  • … and so would need to return the array.

Guidance

Examiner’s Comments

Many candidates struggled to go beyond recall of definitions for calling by reference and calling by value and struggled to apply it to the code given and to provide a detailed explanation.

The bubble sort was defined as a procedure and not a function, so if numbers had been passed by value, a copy of the array would have been passed, and any changes made would not have been kept after the procedure had completed execution.

out of 3

23(b)(ii) 1 mark

The programmer has used a for loop on line 3 in the procedure bubbleSort. A for loop is a count controlled loop.

State what is meant by the term ‘count controlled loop’.

Mark scheme 23(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

A loop that repeats a fixed / set number of times

Guidance

Examiner’s Comments

Most candidates could accurately define a ‘count controlled loop’ as one that repeated a predefined number of times, although some candidates gave an ambiguous response that was equally applicable to a conditional loop.

out of 1

23(b)(iii) 3 marks

State the purpose of the variable holdValue in the procedure bubbleSort.

Mark scheme 23(b)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

  • To temporarily hold a value (for numbers[x])…

  • …while it is being transferred from one position to another…

  • ….in the array numbers

  • To stop values over writing each other

Guidance

Examiner’s Comments

Many candidates found it difficult to explain the purpose of the
holdValue variable in context. Where candidates achieved some of the marks, they most

frequently identified holdValue as a temporary store that was required to prevent accidental overwriting of data during the swap process. Relatively few were able to accurately describe how the variable allowed the contents of

dataArray[x] and

dataArray[x+1] to be swapped.

Exemplar 1

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

A candidate's handwritten answer:

It acts as a temporary variable to hold value of numbers [x] while before sum is overwritten so the original value is lost and is instead copied to numbers[x+1]

This exemplar very clearly states exactly how and why the variable holdValue is required.

out of 3

23(b)(iv) 2 marks

The procedure bubbleSort will only partially sort the array numbers into order.

Describe what the programmer would need to add to the algorithm to enable it to fully sort the numbers into order.

Mark scheme 23(b)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

  • Add a (second outer) loop

  • That will repeat for each pass / repeat until the flag is set to true at the end of a pass

Guidance

Examiner’s Comments

Many candidates found it challenging to apply knowledge of a bubble sort to the code given. While a pleasing number identified the need to have an outer loop, there were far fewer who were able to expand on this to explain that this was required to repeat the process for the requi red number of passes, or until no swaps had occurred during a pass.

out of 2

Question 24

2 marks

24 2 marks

A card game uses a set of 52 standard playing cards. There are four suits; hearts, diamonds, clubs and spades. Each suit has a card with a number from; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13.

The card game randomly gives 2 players 7 cards each. The unallocated cards become known as the deck.

The players then take it in turns to turn over a card. A valid move is a card of the same suit or the same number as the last card played.

The winner is the first player to play all of their cards.

The cards are held in the 2D array cards. The first index stores the card number and the second index stores the suit, both as strings.

Write a pseudocode statement or program code to declare the array cards.

Mark scheme 24

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • identifier cards…

  • …with 2 dimensions

Guidance

Examiner’s Comments

Many candidates gained a mark by initialising the identifier cards, but fewer gained the second mark for correctly setting it to be a two-dimensional

structure. Many obscure forms of syntax were observed, but marks was given if it was clear that the structure was two- dimensional, however, for many responses, it was clear that a one- dimensional list had been initialised.

out of 2

Question 25

9 marks

25(a)

A program uses the recursive function calculate(). The function is written in pseudocode.

1. function calculate(number : byVal)
2.   if number == 1 then
3.     return number
  1. else
5.     return number + calculate (number - 1)
  1. endif
7. endfunction

25(a)(i) 1 mark

Give the line number in the algorithm calculate() where a recursive call is made.

Mark scheme 25(a)(i)

Line number 5

Guidance

Examiner’s Comments

Nearly all candidates gave the correct answer line 5.

25(a)(ii) 2 marks

State two features of any recursive algorithm.

Feature 1

Feature 2

Mark scheme 25(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per feature

  • A function that calls itself / a function that is defined in terms of itself

  • …has a base case (that terminates the recursion)

Guidance

Examiner’s Comments

Most candidates knew that a recursive algorithm is self-referential and calls itself, but some candidates were too vague specifying that it ‘calls a function’. Candidates often found it harder to gain the second mark and some gave answers not related to the question such as explanations of how recursion uses stack frames during execution. Technical vocabulary is important, and some candidates did not make it clear that recursion has a base case. Those that stated a
stopping/terminating condition needed to qualify their response to say that these conditions stopped/halted the recursion. Where candidates just wrote ‘stopping condition’ it was too vague as it was unqualified since they could have been talking about any conditional loop.

out of 2

25(b) 5 marks

Trace the recursive function calculate() and give the final return value, when the following function call is run:

calculate(5)

You may choose to use the table below to give your answer.

Function callnumberreturn
calculate(5)
Mark scheme 25(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Guidance

Examiner’s Comments

out of 5

25(c) 1 mark

Give the pseudocode function call that would return 55 from the recursive function calculate().

Mark scheme 25(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

calculate(10)

Guidance

Examiner’s Comments

Those candidates who scored full marks in 7b had little difficulty giving the correct call
calculate(10). Some candidates just wrote 10, which did not answer the question. Those who showed little
understanding of recursion in 7b rarely gave the correct answer in 7c.

out of 1

Question 26

16 marks

26(a) 1 mark

A computer program is being written to store data about students.

Fig. 2 shows a binary search tree that stores data about students.

Each student is represented by their ID number. The current contents of the binary search tree are:

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["2005"] ---|left| B["1920"]
    A ---|right| C["2350"]
    B ---|left| D["1500"]
    B ---|right| E["1985"]
    C ---|left| F["2100"]
    C ---|right| G["2560"]
    E ---|left| H["1952"]
    E ---|right| I["2000"]

Fig. 2

Identify the root node in the binary tree shown in Fig. 2.

Mark scheme 26(a)

2005

Guidance

Examiner’s Comments

Most candidates correctly identified the root node as 2005.

26(b) 2 marks

Identify two leaf nodes in the binary tree shown in Fig. 2.

1

2

Mark scheme 26(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each to max 2

  • 1500

  • 1952

  • 2000

  • 2100

  • 2560

Guidance

Examiner’s Comments

Most candidates correctly identified valid leaf nodes, but a significant number erroneously gave 1920 and 2350 as the child nodes of the root instead of identifying leaf nodes.

out of 2

26(c) 4 marks

Four more students are added to the binary search tree shown in Fig. 2 in this order:

1420 2050 2780 2600

Complete the binary search tree here by adding the new students to it.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["2005"] ---|left| B["1920"]
    A ---|right| C["2350"]
    B ---|left| D["1500"]
    B ---|right| E["1985"]
    E ---|left| F["1952"]
    E ---|right| G["2000"]
    C ---|left| H["2100"]
    C ---|right| I["2560"]
Mark scheme 26(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each in the correct place

  • 1420

  • 2050

  • 2780

  • 2600

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["2005"] ---|left| B["1920"]
    A ---|right| C["2350"]
    B ---|left| D["1500"]
    B ---|right| E["1985"]
    D ---|left| F["1420"]
    D ---|right| G[" "]
    E ---|left| H["1952"]
    E ---|right| I["2000"]
    C ---|left| J["2100"]
    C ---|right| K["2560"]
    J ---|left| L["2050"]
    J ---|right| M[" "]
    K ---|left| N[" "]
    K ---|right| O["2780"]
    O ---|left| P["2600"]
    O ---|right| Q[" "]
    P ---|left| R[" "]
    P ---|right| S[" "]

Guidance

Examiner’s Comments

Many candidates scored at least 2 marks, but many erroneously inserted 2600 before 2780, or just put 2600 as the left child node of 2560. A common mistake was to use straight lines for new child

nodes rather than clearly indicating whether the new child node was a left/right child of the parent node.

out of 4

26(d) 9 marks

* A programmer would like to traverse the binary search tree shown in Fig. 2.

Compare the use of a breadth-first traversal and a depth-first (post-order) traversal on the binary search tree.

You should include the following in your answer:

  • how each traversal works
  • the order of the return values for each traversal.
Mark scheme 26(d)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level
(7-9 marks)
The candidate demonstrates a thorough knowledge and understanding of search traversals; the material is generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided. Evidence/examples will be explicitly relevant to the explanation.
There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level
(4-6 marks)
The candidate demonstrates reasonable knowledge and understanding of search traversals; the material is generally accurate but at times underdeveloped.
The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate provides a reasonable discussion, the majority of which is focused. Evaluative comments are, for the most part appropriate, although one or two opportunities for development are missed.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence.

Mark Band 1 – Low Level
(1-3 marks)
The candidate demonstrates a basic knowledge of search traversals with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and understanding to the context provided.
The candidate provides a limited discussion which is narrow in focus. Judgements if made are weak and unsubstantiated. The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 marks
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding Indicative content

  • Breadth first takes first value then visits all nodes connected to it. It then takes all nodes connected to those nodes.
  • Depth first goes to the left node, this becomes a new tree. It continues going to the left until a leaf. It then returns this, then goes right and repeats from the start. Follow left, follow right, take root.

AO2: Application

  • Breadth will return 2005 1920 2350 1500 1985 2100 2560 (1420) 1952 2000 (2050) (2780) (2600)
  • Post-order / Depth will return (1420) 1500 1952 2000 1985 1920 (2050) 2100 (2600) (2780) 2560 2350 2005

AO3: Evaluation Evaluations may vary and include one or more of the following points:

  • Breadth is more efficient when the data searched for is closer to the root.

  • Depth is more efficient when data to be search for is further down.

  • Depth memory requirement is linear

  • Depth can be written recursively to aid understanding.

  • Breadth in general is better time complexity

  • In large trees depth may never return a value

Candidates are not expected to know the complexities for the search traversals, however credit should be awarded if candidates choose to include these.

Limit to band 2 if there is no evaluation of BFS/DFS

Examiner’s Comments

Many candidates achieved some marks, but a few did confuse Breadth-first search (BFS) and Depth- first search (DFS), getting them the wrong way round.

Most had a much clearer understanding of BFS than DFS and were able to score marks in Level 1 for showing how a BFS would be carried out. Fewer managed to accurately show how a DFS would work. While there was an understanding that DFS would traverse leftward to the lowest leftmost node, descriptions of back tracking were not given as many marks. A common

mistake made with DFS was to output the nodes in the order they were first visited rather than the order in which they are output.

Few could describe the mechanics of the algorithms with BFS using a queue and DFS using a stack. Those who did achieved the top of Level 2.

Very few candidates could give exemplar uses of BFS or DFS (e.g. deleting nodes in a tree) or compare cases where they might be used (e.g. distance of target node(s) from root), with very little evaluation. This meant there were very few Level 3 responses seen.

out of 9

Question 27

21 marks

27(a) 5 marks

A bubble sort will sort an array of 50 integer values called numberArray.

This bubble sort algorithm is written to sort numberArray into ascending numerical order.

Complete this bubble sort algorithm.

arrayLength = ……
tempValue = 0
do
  flag = false
  for y = 0 to arrayLength - ……
   if numberArray[y] > numberArray[y + 1] then
    …… = numberArray[y]
    numberArray[……] =
numberArray[y + 1]
    numberArray[y + 1] = ……
    flag = true
   endif
  next y
until flag == false
Mark scheme 27(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each completed statement

arrayLength = 50 / numberArray.length
tempValue =0
do
  flag = false
  for y = 0 to arrayLength - 2
   if numberArray[y] > numberArray[y + 1]
then
    tempValue = numberArray[y]
    numberArray[y] = numberArray[y + 1]
    numberArray[y + 1] = tempValue
    flag = true
   endif
  next y
until flag == false

Guidance

Note if numberArray - 1 / 49 used, then for loop for y will need to be 0 to arrayLength - 1

Allow other suitable valid identifier in place of tempValue e.g. temp

Examiner’s Comments

Many candidates scored at least 1 mark for correctly initialising the arrayLength, although some erroneous

length.arrayLength

rather than

arrayLength.length

answers were seen. If candidates are assuming the existence of inbuilt methods they should reference them in the correct OOP way.

Very few candidates achieved the second marking point for the loop. A very common off-by-one error was seen with the value 1 given. If arrayLength was set to 50 this would cause a run time error for an out-of- bounds reference when the loop ran.

Some candidates tried to swap the array values directly in a Pythonic style that was not suitable for a pseudocode solution in context, and some used incorrectly formatted variable identifiers.

Variable identifiers Valid identifiers must be single words. In a number of instances, it was clear that tempValue was given as temp Value. Where candidates give an answer that clearly has spaces within an intended identifier name no marks will be given.

out of 5

27(b) 4 marks

One section of numberArray is shown here.

2121935157

A second sorting algorithm that could be used to sort this data is a merge sort.

Show how a merge sort will sort this section of the array numberArray into ascending numerical order.

Mark scheme 27(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each stage shown

  • Splitting into individual items

2 12 1 9 3 5 15

  • Combining in pairs

2 12 1 9 3 5 7

  • Merge pairs

7

4

1 2 9 12 3 5 7 15

Merge for final
1 2 3 5 7 9 12 15

Guidance

Do not award a mark for the final stage, unless candidate has shown the previous sorting stage(s).

Examiner’s Comments

Many candidates presented very clear solutions that used the values in numberArray to construct clearly annotated diagrams. Textual prose responses tended to either not refer at all to the given data set, or mentioned it only partially, so lost marks. There was occasional confusion with other

sorting algorithms, but this was seen relatively infrequently,

Where errors were made candidates did not split the data to the atomised level. Many did not fully understand how a merge sort works by merging two separate lists of ordered values together but performed in-place sorts in sub-lists.

[An examiner's marking symbol, not shown here.]

Misconception

The merge phase in a merge sort takes two separate lists that are already ordered. Values in those two separate lists are taken and merged in sequence to form a new list. E.g. List 1 [1, 9] and List 2 [2, 10] are taken and merged 1 from List 1, 2 from List 2, 9 from List 1 and then 10 from List 2, into a new List.

Values in lists [1, 9] and [2, 10] are not placed in a list [1, 9, 2, 10] and then sorted in-situ. A significant number of candidates thought that a merge sort split lists up until values were in pairs and showed [15, 7] going directly to [7, 15] (i.e. an in-situ sort) without first being atomised into two separate lists of [15] and [7] and then being merged to give [7, 15].

Exemplar 2

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

The image shows a handwritten diagram titled "Exemplar 2" illustrating a process of splitting and merging sets of numbers.

At the top, there are three rows of numbers in boxes:

  1. [2] [12] [1] [9] and [3] [5] [15] [7]
  2. [2] [12] and [1] [9] and [3] [5] and [15] [7]
  3. [2] [12] [1] [9] and [3] [5] [15] [7] (with arrows pointing from the second row to these boxes)

Below these, there is a section labeled "splitting:" showing the numbers grouped: 2, 12 and 1, 9 and 3, 5 and 7, 15

Below that, there is a section labeled "merging:" showing the groups being combined: 1, 2, 9, 12 and 3, 5, 7, 15

At the very bottom, the final merged set is shown: 1, 2, 3, 5, 7, 9, 10, 15 (Note: the '10' appears to be a handwritten addition or correction in the final line).

Candidate responses to questions that require ‘showing’ how data sets are ordered by sorting algorithms are best tackled by using clearly annotated diagrams such as this exemplar response.

out of 4

27(c) 12 marks

* Another sorting algorithm is insertion sort.

The number of values stored in the array numberArray has been reduced to 10.

Compare the use of bubble, merge and insertion sorts on the array numberArray.

You should include the following in your answer:

  • how each algorithm works
  • the Big O complexities for each algorithm
  • the suitability of each algorithm for sorting the 10 values.
Mark scheme 27(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level
(9-12 marks)
The candidate demonstrates a thorough knowledge and understanding of sorting algorithms; the material is generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided. Evidence/examples will be explicitly relevant to the explanation.
There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level
(5-8 marks)
The candidate demonstrates reasonable knowledge and understanding of sorting algorithms; the material is generally accurate but at times underdeveloped.
The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate provides a reasonable discussion, the majority of which is focused. Evaluative comments are, for the most part appropriate, although one or two opportunities for development are missed.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence.

Mark Band 1 – Low Level
(1-4 marks)
The candidate demonstrates a basic knowledge of sorting algorithms with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and understanding to the context provided.
The candidate provides a limited discussion which is narrow in focus. Judgements if made are weak and unsubstantiated. The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 marks
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding Indicative content

  • Merge sort splits data into individual lists and merges
  • Insertion makes first value sorted list, then inserts each item into the sorted list
  • Bubble sort looks through each item in turn, number of items times

AO2: Application

  • Merge uses more memory as new lists are needed. Insertion and Bubble need constant memory.

  • Bubble and Insertion have the best best-times, both O(n) because they run through the data once. merge sort requires a minimum number of stages so best case is longer (O(n log(n))

  • Merge average is the same as best. Insertion and Bubble has average o(n^2).

  • Worst time merge has same has best and average because same number of stages are needed. Bubble sort and insertion all have worse O(n^2)

AO3: Evaluation

  • There are a small number of elements (10) therefore a bubble sort of insertion would be better space wise because no further space is needed.
  • Merge would not need excessive amounts of more memory as there are only a small number of elements.
  • Time complexity, there is a small number of elements therefore Bubble and Insertion may be preferable. Differences are unlikely to be significant, so either would be more appropriate.

Examiner’s Comments

Most candidates could describe the basic elements of each of the bubble, merge and insertion sort, although some had difficulty remembering insertion sort and confused it with quick sort.

Many candidates

struggled to show accurate knowledge of the Big O time complexity values for
best/average/worst case for the three algorithms, which is a learnt response. Some did give very good examples of where bubble and insertion sort would give best/worst case times.

Very few candidates could cite space complexity, and where they did a number thought bubble/insertion were space complexity O(n) because there are n elements rather than O(1) which means constant with no extra memory overhead.

There was some evaluation of the number of items being sorted in most cases.

Overall, many responses were clustered in Level 2, but a pleasing number of candidates achieved Level 3 with clear and detailed descriptions, accurate Big O values, and an evaluation of the size of the data set being sorted.

out of 12

Question 28

9 marks

28(a) 1 mark

Fig. 5 shows a graph data structure representing a small section of a parcel delivery network. Each node represents an address where deliveries need to be made. The edges show the possible routes and distances between these deliveries.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A ---|3| B
    B ---|7| D
    B ---|3| E
    D ---|3| C
    D ---|11| H
    C ---|7| E
    E ---|3| F
    F ---|7| G
    G ---|3| H

Fig. 5

Give one reason why the graph is a visualisation of the problem.

Mark scheme 28(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

28(a) (1 mark)

1 mark e.g.

  • Symbols are used to represent the address

  • The edges represent possible connections between addresses not the actual physical routes

Guidance

Allow other suitable answers that are in context of the problem

Examiner’s Comments

Very few candidates were able to give suitable answers within the context of the problem. The question was asking why the graph in Fig 5 was a visualisation. Few

candidates identified that it was because the letters at the nodes represented delivery addresses, while the weights on the edges represented the road distances between the addresses. Most candidates gave descriptions of
visualisation in general rather than answering in context.

28(a)(ii) (2 marks)

1 mark per bullet
Similarity:

  • Both always find the shortest route

  • Both are pathfinding algorithms

Differences:

  • A* is (usually) more efficient / dijkstra’s is (usually) slower

  • A* uses heuristics to find a solution faster / Dijkstra’s does not use heuristics

Guidance

Must contain a similarity and a difference for both marks.

Examiner’s Comments

Those candidates who scored well in c(i) frequently gained full marks for describing the similarities and differences between Dijkstra’s algorithm and the A* algorithm. The most common responses were that both give the shortest path and that A* uses heuristics.

out of 1

28(b)(i) 6 marks

Show how Dijkstra’s algorithm can be used on the graph shown in Fig. 5 to find the shortest path from the start node A and the end node H.

You should state the nodes on the final path and the overall distance. Show your working.

You may choose to use the table below to give your answer.

NodeDistance travelledPrevious node

Final path: ……

Distance: ……

out of 6

28(b)(ii) 2 marks

Give a similarity and difference between the performance of Dijkstra’s algorithm and the performance of A* algorithm.

Similarity

Difference

out of 2

Question 29

5 marks

29

A computer program stores data in an array named words.

The data in the array needs to be searched for a value that the user inputs.

29(i) 1 mark

One example of a searching algorithm is a binary search.

Identify the precondition for a binary search.

Mark scheme 29(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

The array/data must be in order/sorted

Guidance

Examiner’s Comments

Most candidates successfully identified that data must be ordered as a precondition for a binary search. A few candidates were too vague giving unqualified answers such as ‘must be sorted’, without specifying what had to be sorted.

out of 1

29(ii) 4 marks

A second example of a searching algorithm is a linear search.

Describe how a linear search works.

Mark scheme 29(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • Compare the search item with the first value

  • ….then compare the search item with the next value

  • ….repeat the above process until either

  • ….the end of the array has been reached or

  • ….the search item is found and then stop

  • ….then return the array position / return -1 / False if not found

Guidance

Not all mark points are dependent, but points awarded must following logically in sequence.

Examiner’s Comments

Many candidates scored some marks for describing the steps involved in a linear search, but relatively few presented a comprehensive and detailed description for full marks. Many responses used vague language such ‘checking if the value is found’ without explaining that a comparison between the current term and the target search value must be performed. Other examples of vague

language use included responses such as ‘keep going until you find what you’re looking for’, which begged the question, how do you know when you’ve found what you’re looking for?

Common errors included candidates who mistakenly described a binary search, and those who did not answer the question. Examples of not answering the question included giving properties of a linear search such as its linear run time or the fact that it can be run on an unordered data set.

out of 4

Question 30

10 marks

30(a) 3 marks

A veterinary surgery uses a two dimensional array to store bookings for customers to bring in their animal to see the vet. There are ten possible booking slots during each day.

An example of the two dimensional array is shown in Fig. 1.

  • The first column stores the booking slot number, ranging between 1 and 10.
  • The second column stores the time of the appointment.
  • The third column stores the customerID of the customer who has booked that slot.
19:005877RC
29:309655AS
310:00
410:308754TT
511:00
611:308745SD
713:009635GH
813:30
914:009874PL
1014:309658SV

Fig. 1

If a customerID has been entered for a booking slot then the booking slot has been taken. If no customerID has been entered then the booking slot is available for booking.

When customers make an appointment they often ask for the first available booking slot.

Describe how a linear search could be used for this purpose.

Mark scheme 30(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 3 marks, e.g.:

  • To start from the beginning / first booking slot

  • Search each slot in order / sequentially

  • Search until the first empty slot is found

Guidance

Examiner’s Comments This question was generally not well answered. Candidates found it difficult to articulate a clear and concise set of steps that take place during a linear search. Many responses were vague and not directly related to a linear search being performed on the data presented in the table.

out of 3

30(b) 7 marks

A function findFirst, is used to find the first available appointment.

Write the function findFirst that will find the first available appointment and return the booking slot number. If no appointments are available then the function should return "-1".

You should write your function using pseudocode or program code.

Mark scheme 30(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 7 marks, e.g.:

  • Defining the findFirst function correctly

  • Suitable logic for checking the first time slot

  • Suitable logic for checking the next time slot…

  • Suitable loop to check all time slots

  • Suitable logic for returning the available time slot

  • Suitable logic for returning -1 if no time slots available

  • Suitable use of variable names and indentation

Guidance

Example solution:

function
findFirst()
   count = 0
   do
     found =
false
     if
customerID[2,
count] == "" then
       found =
true
     else
       count =
count + 1
     endif
   until count ==
10 or found == true
   if found == True
     return
customerID[0,count]
   else
     return -1
   endif
endfunction

There are many different ways that this function could have been achieved. Therefore other alternative methods should be given credit.

Examiner’s Comments A number of candidates started by defining a procedure rather than defining a function. Indentation was not always consistent with the constructs being used. Candidates seemed to have difficulty with referencing two dimensional structures. Algorithms that require two dimensional data frequently appear on this paper and candidates need to have extensive practical programming experience solving problems using these structures.

Exemplar 2

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

approximations = [array]
function FindFirst(i):
    length = length(approximations.length())
    maxValue = -1
    index = 0
    found = False
    while found == False and index < length:
        if approximations[index] > maxValue then
            maxValue = approximations[index]
            found = True
        else
            index = index + 1
    endwhile
    return
    return maxValue
end function

A well-structured pseudocode response that uses indentation and variable naming well. The

logic of the loop to check each item in sequence for an empty entry is clear, as is the indexing into the 2- Dimensional table structure.

Exemplar 3

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

A candidate's handwritten answer:

[unclear] [unclear] [unclear] [unclear] If [unclear] appointments available, find first appointment available, if [unclear] [unclear] // If not one appointment [unclear] appointment available, plus is the first [unclear] appointment // If this prints the first appointment.

If not no appointments available, return -1

[unclear] [unclear]

To contrast with Exemplar 2, this exemplar shows a lack of pseudocode with a response written mostly in prose English, with inconsistent indentation and a lack of clear variable naming.

[An examiner's marking symbol, not shown here.]

Assessment for learning

Candidates frequently benefit from having extensive practical programming experience when answering pseudocode questions.

Past paper questions can provide a context for problems for
implementation. For this question candidates could either be asked to code a two dimensional table structure for the data in Fig 1 and to then implement the linear search, or they code be provided with a scaffolded partially complete solution with the table defined and the stem of a function given.

Routinely taking past paper questions that can be practically implemented is an effective way to make sure that candidates have relevant experience.

out of 7

Question 31

10 marks

31(a) 4 marks

Trudi would like to sort an array of numbers into order.

The numbers before they have been sorted can be seen here.

8925753745

Trudi will use a bubble sort to put these numbers into order from smallest to largest.

Show the first pass of the bubble sort. You should clearly show each comparison made.

Mark scheme 31(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each correct row up to a maximum of 4 marks.

8925753745
2589753745
2575893745
2575378945
2575374589

1 mark 1 mark 1 mark 1 mark

Guidance

Marks should be awarded for correct swapping of adjacent items that are out of order. Therefore if the previous step is incorrect but the candidate has followed through with the correct answer then marks should be awarded.

Examiner’s Comments There were a number of responses that included clear diagrams illustrating the first pass of a bubble sort on the given data. Very few candidates confused bubble sort with other types of sorting algorithm so most achieved full marks for this question.

out of 4

31(b)

Trudi has written a procedure, bubbleSort.

01 procedure bubbleSort(numbers)
02      do
03         sorted = true
04         for count = 0 to numbers.length -2
05            if numbers[count] > numbers[count+1] then
06               temp = numbers[count+1]
07               numbers[count+1] = numbers[count]
08               numbers[count] = temp
09               sorted = false
10            endif
11         next count
12      until sorted == true
13 endprocedure

31(b)(i) 1 mark

Identify a line in the procedure bubbleSort where a decision is taken.

Mark scheme 31(b)(i)
  • Line 5

Guidance

Allow line 4 and 12

Examiner’s Comments Most candidates had little difficulty identifying line 05 as the obvious response, but some candidates did choose the decision taking place at the end of the do..until loop in line 12.

31(b)(ii) 1 mark

Identify the name of the parameter used in the procedure bubbleSort.

Mark scheme 31(b)(ii)

numbers

Guidance

Examiner’s Comments Nearly all candidates correctly identified numbers as the correct parameter name.

31(b)(iii) 2 marks

Describe the purpose of the temp variable in the procedure bubbleSort.

Mark scheme 31(b)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 2 marks, e.g.:

  • To temporarily hold data…

  • …To allow the contents of two variables to be swapped

  • …to ensure that data is not overwritten

Guidance

Examiner’s Comments Candidates found it difficult to articulate a response that broke the purpose of the temp

variable down in lines 06 to 08 into logical steps with reasons. Many candidates identified it as a temporary store, but few could explain that it allowed the contents of the two array positions to be swapped without erroneously overwriting either value.

out of 2

31(b)(iv) 2 marks

Describe the purpose of the sorted variable in the procedure bubbleSort.

Mark scheme 31(b)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 2 marks, e.g.:

  • signifies whether or not any swaps have been made in a pass

  • if still set to true at the end of a pass, then the list is sorted

Guidance

Examiner’s Comments Many responses to this question were generalised answers that stated that the sorted variable determined whether the data was sorted or not. This could be an indication that candidates did not have practical experience of implementing a bubble sort with a swap flag. Most candidates did not appreciate the function of the variable during each pass of the bubble sort. Candidates need to be well versed in the different ways of implementing a bubble sort.

out of 2

Question 32

40 marks

32(a)

A Nonogram is a logic puzzle where a player needs to colour in boxes. The puzzle is laid out as a grid and each square needs to be either coloured black or left white.

The numbers at the side of each row and column tells the player how many of the boxes are coloured in consecutively. Where a row has two or more numbers, there must be a white square between the coloured squares.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

12301
211
211
1111
3111
11

In this example:

the first column has 1 1, this means there must be two single coloured boxes in this column. There

  • must be at least 1 white box between them.
  • the first row has 2, this means there must be two consecutively coloured boxes in the row.

Juan is creating a program that will store a series of Nonograms for a user to play. The game will randomly select a puzzle and display the blank grid with the numbers for each row and column to the user.

The user plays the game by selecting a box to change its colour. If the box is white it will change to black and if it is black it will change to white. The user can choose to check the answer at any point, and the game will compare the grid to the answers and tell the user if they have got it correct or not.

Juan is creating a structure diagram to design the game.

32(a)(i) 3 marks

Complete the structure diagram by adding another layer for New game, Play game and Check answer.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["Nonogram"] ---|left| B["New game"]
    A ---|middle| C["Play game"]
    A ---|right| D["Check answer"]
    B ---|left| E[" "]
    B ---|right| F[" "]
    C ---|left| G[" "]
    C ---|right| H[" "]
    D ---|left| I[" "]
    D ---|right| J[" "]
Mark scheme 32(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per box up to a maximum of 3 marks.

  • Select puzzle and display blank grid (below new game)

  • Select box and change colour of boxes (below play game)

  • Compare to answer and display correct/incorrect (below check answer)

e.g.

[Image redrawn from the original mark scheme by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["Tetris game"]
    A ---|left| B["Draw game"]
    A ---|middle| C["Play game"]
    A ---|right| D["Check answer"]
    B ---|left| E["Select puzzle"]
    B ---|right| F["Display blank grid"]
    C ---|left| G["Select box"]
    C ---|right| H["Change colour of boxes"]
    D ---|left| I["Compare to answer"]
    D ---|right| J["Display correct/incorrect"]
out of 3

32(a)(ii) 2 marks

A structure diagram is one method of showing the decomposition of a problem.

Explain why decomposing a problem can help a developer design a solution.

Mark scheme 32(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 2 marks, e.g: e.g.

  • Splits the problem into smaller chunks

  • Smaller problems are more manageable

  • Smaller problems are easier to solve

  • To see where code can be reused in the solution

  • To split tasks between different programmers

out of 2

32(a)(iii) 3 marks

Identify one input, one process and one output required for the game.

Input

Process

Output

Mark scheme 32(a)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for input, 1 for process 1 for output
e.g.
Input:

  • Clicking a box

Process:

  • Generating new puzzle

  • Checking if block is black

  • Changing block to white

Output:

  • Grid with coloured squares

out of 3

32(b)

Juan uses the structure diagram to create a modular program with a number of subroutines. The program will use two integer 2-dimensional arrays to store the puzzles:

  • puzzle(5,5) stores the solution
  • answerGrid(5,5) stores the user’s current grid.

A 0 represents a white box and a 1 represents a black box.

32(b)(i) 5 marks

Juan creates a function, countRow(), to count the number of coloured boxes in one row and return the number of consecutive coloured boxes in that row. If there is more than one set of coloured boxes in the row, these are joined together and the string is returned. For example, in the following grid countRow for row 0 will return "2" as a string, and countRow for row 2 will return "1 1" as a string. If there are no 1s in a row, then "0" is returned as a string.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

11000
01100
00101
11100
01000

Complete the pseudocode algorithm countRow().

01   function countRow(puzzle:byref, rowNum:byval)
02   count = 0
03   output = " "
04   for i = 0 to ……
05    if puzzle[rowNum, i] == …… then
06      count = count + 1
07    elseif count >= 1 then
08      output = output + str(……) + " "
 09      count = 0
10    endif
11   next i
12   if count>= 1 then
13      output=output+str(count)
14   elseif output == "" then
15      output = "……"
16   endif
17   return ……
 18 endfunction
Mark scheme 32(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each correctly completed statement up to a maximum of 5 marks:

function countRow(puzzle:byref,
01
rowNum:byval)
02   count = 0
03   output = " "
04   for i = 0 To 4
05    if puzzle[rowNum, i] == 1
   then
06     count = count + 1
07    elseif count >= 1 then
08     output = output +
    str(count) + " "
09     count = 0
10    endif
11   next i
12   if count>= 1 then
13     output=ouput+str(count)
14   elseif output == "" then
15     output = "0"
16   endif
17   return output
  18 endfunction

Guidance

Accept

for i = 0 to row.length-1

for i = 0 to row.length

for i=0 to 5

out of 5

32(b)(ii) 2 marks

Explain the purpose of line 03 in the function countRow.

Mark scheme 32(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 2 marks, e.g:

  • Initialise the variable output…

  • …with a space

  • …for use later on in the code…

  • …So it can be used for concatenation later in the code …

  • …to avoid an error being generated

out of 2

32(b)(iii) 3 marks

Describe the purpose of branching and iteration in the function countRow.

Mark scheme 32(b)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 3 marks, e.g:

  • check the value stored in each index

  • check whether it is at the end of a row

  • check whether each row has been given an output or not

out of 3

32(b)(iv) 6 marks

The procedure displayRowAnswer() takes puzzle as a parameter and outputs the value in each box. Each box in a row is separated by a space. At the end of each row there are two spaces and (by calling the function countRow from part (i)) the clue values for that row.

For example the puzzle below:

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

11000
01100
00101
11100
01000

Would output:

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

110002
011002
001011
111003
010001

Write pseudocode or program code for the procedure displayRowAnswer().

Mark scheme 32(b)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 6 marks:

  • Procedure heading for displayRowAnswer

  • …taking puzzle as parameters

  • Nested loops through all array elements

  • …outputting all rows

  • … at the end of each row calling countRow ….

  • …..with parameters puzzle and the current loop counter

e.g.

procedure displayRowAnswer(puzzle)
  for i = 0 To 4
   for j = 0 To 4
    print(puzzle[i, j] + " ")
   next j
   print (" " + countRow
   (puzzle, i))
  next i
endprocedure

Guidance

Accept

for i = 0 to row.length-1

for i = 0 to row.length

for i=0 to 5

out of 6

32(b)(v) 3 marks

The function checkWon() takes answerGrid and puzzle as parameters and compares each element in the grids. If they are identical, it returns true, otherwise returns false.

01   function checkWon(puzzle)
02   for row = 0 to 4
03    for column = 0 to 4
04      if puzzle[row, column] == answerGrid[row, column] then
 05       return false
06      endif
07    next column
08   next column
09   return true
 10   endfunction

There are three logic errors in the function checkWon

State the line number of each error and give the corrected line.

Error 1 line number

Error 1 correction

Error 2 line number

Error 2 correction

Error 3 line number

Error 3 correction

Mark scheme 32(b)(v)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for clearly identifying each error and giving the correction.

  • Line 01 needs answerGrid as parameter

  • Line 04 == should be !=

  • Line 08 should be next row

Guidance

Do not award marks for line numbers alone without stating the error.

Consider 1 mark for not changing line 04 but changing 05 to true and 09 to False

out of 3

32(c) 9 marks

* Juan passed the two arrays as parameters, but he did consider making them globally accessible.

Compare the use of global and local variables and data structures in this program. Include the use of parameters and program efficiency in your answer.

Mark scheme 32(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level (7-9 marks)
The candidate demonstrates a thorough knowledge and understanding of local and global variables; the material is generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided.
Evidence/examples will be explicitly relevant to the explanation.
The candidate is able to weigh up the use of both local and global variables which results in a supported and realistic

judgment as to whether it is possible to use them in this context.
There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level (4-6 marks)
The candidate demonstrates reasonable knoledge and understanding of local and global variables; the material is generally accurate but at times underdeveloped.
The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate makes a reasonable attempt to come to a conclusion showing some recognition of influencing factors that would determine whether it is possible to use local and global variables in this context.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence

Mark Band 1 – Low Level (1-3 marks)
The candidate demonstrates a basic knowledge of local and global variables with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and understanding to the context provided. The candidate provides nothing more than an unsupported assertion.
The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 marks
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding Indicative content Local variables:

  • Scope within the module defined within
  • Cannot access externally unless passed as

parameter, or returned from function

  • When module is exited, memory of variable is freed

Global variables:

  • Scope within the entire program
  • Can access from anywhere
  • Retained in memory permanently

ByRef Points to location of variable
ByVal Sends the value

AO2: Application

  • If global the arrays can be accessed from all modules by direct reference
  • If local to the main, the arrays will need to be passed as parameters byreference
  • Can send ByVal – but not always possible with arrays in some languages
  • Modules are self contained and then can be reused in other programs he wants to create without needing to take the global variables with them

AO3: Evaluation e.g.

  • +ve Local = memory efficient
  • +ve Global = easier programming,

simpler to follow, easier to debug

  • -ve Global = memory inefficient, not good programming technique
  • -ve Local = more difficult to trace/debug/follow where the values are passed
  • Relatively small program – don’t know about overall plan for it, it might not be memory intensive, unlikely anyone else is going to access/amend e.g. use as a library – therefore global would not waste significant resources
out of 9

32(d) 4 marks

Juan wants to create a program that will generate new Nonograms with different grid sizes. For example a Nonogram with a 10 × 10 grid or a 5 × 20 grid.

Describe how the program could be written to automatically generate a new Nonogram.

Mark scheme 32(d)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 4
e.g.

  • Make use of random numbers

  • Generate an x/horizontal size for the grid

  • Generate a y/vertical size for the grid

  • Loop through each row/column

  • …generate a number between 0 and the number of rows/columns (depending on MP4 answer)

  • Loop through each box

  • …generate a 1 or 0 to store in it

out of 4

Question 33

19 marks

33(a) 5 marks

Christoff is writing a program to simulate a city using object-oriented programming. He is designing classes to store different types of buildings and their location on the road. He has created the following plan for some of the buildings:

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

classDiagram
    class building {
        -numberFloors
        -width
        -height
        +new(pFloors, pWidth, pHeight)
        +getNumberFloors()
        +getWidth()
        +getHeight()
        +setNumberFloors(pFloors)
        +setWidth(pWidth)
        +setHeight(pHeight)
    }
    class office {
        -numDesks : integer
        -numCompanies : integer
        +new(pFloors, pWidth, pHeight, pDesks, pCompanies)
        +getDesks()
        +getCompanies()
        +setDesks(pDesks)
        +setCompanies(pCompanies)
    }
    class house {
        -Bedrooms
        -bathrooms
        +new(pFloors, pWidth, pHeight, pBedrooms, pBathrooms)
        +getBedrooms()
        +getBathrooms()
        +setBedrooms(pBedrooms)
        +setBathrooms(pBathrooms)
    }
    building <|-- office
    building <|-- house

Part of the declaration for the class building is shown.

Complete the pseudocode declaration by filling in the missing statements.

class building
   private numberFloors
   private width
   private ……
   public procedure new(pFloors, pWidth, pHeight)
     numberFloors = ……
     width = pWidth
     height = pHeight
   endprocedure
   public function getNumberFloors()
     return ……
   endfunction
   public function setNumberFloors(pFloors)
     /sets the value of numberFloors when the parameter is >= 1
     /returns true if numberFloors is successfully changed,
     /returns false otherwise
     if pFloors >= 1 then
      numberFloors = ……
      return true
     else
      return ……
     endif
   endfunction
endclass
Mark scheme 33(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each completed statement up to a maximum of 5 marks:

   private numberFloors
   private width
   private height
   public procedure new(pFloors, pWidth,
pHeight)
     numberFloors = pFloors
     width = pWidth
     height = pHeight
   endprocedure
   public function getNumberFloors()
     return numberFloors
   endfunction
   public function setNumberFloors(pFloors)
     if pFloors >= 1 then
      numberFloors = pFloors
      return true
     else
      return false
     endif
   endfunction
endclass

Guidance

Accept other specific language conventions that would correctly achieve the same outcomes.

out of 5

33(b) 6 marks

Write program code or pseudocode to declare the class house.
Define the attributes and constructor method in your answer. You do not need to write the get or set methods.

Mark scheme 33(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 6 marks:

  • Class declaration for house with inherits building

  • Declaring bedrooms and bathrooms as private

  • New declaration …

  • … with all five parameters

  • Calling super constructor / equivalent with floors, width and height set

  • Setting bedrooms and bathrooms

e.g.

class house inherits building
  private bedrooms, bathrooms
  public procedure new(pFloors,
  pWidth, pHeight, pBedrooms,
  pBathrooms)
   super.new(pFloors, pWidth,
   pHeight)
   bedrooms = pBedrooms
   bathrooms = pBathrooms
  endprocedure
endclass
out of 6

33(c) 4 marks

Christoff develops a new class to store the houses in one road. His class design is shown:

class : houseRoad

attributes:
private buildings(100) /array of class house private numberBuildings /records the number /of houses currently stored in the array /buildings

methods:
new(building)
function getBuilding(buildingNum)
procedure newbuilding(pBuilding)

The method newbuilding() takes a new building as a parameter, and stores this in the next free space in the array buildings.

Write pseudocode or program code for the method newbuilding().

Mark scheme 33(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 4 marks:

  • Procedure header taking parameter

  • Adding parameter to array

  • …at position numberBuildings

  • Incrementing numberBuilding

e.g.

procedure newbuilding(pBuilding)
 buildings[numberBuildings] =
 pBuilding
 numberBuildings =
 numberBuildings + 1
endprocedure
out of 4

33(d) 4 marks

Christoff wants to create a new house called houseOne. It has the properties: 2 floors, 8(m) width, 10(m) height, 3 bedrooms and 2 bathrooms.

The house is located on a road with the identifier limeAvenue of type houseRoad, houseOne is the first house in this road.

Write pseudocode or program code to declare the house houseOne, road limeAvenue and assign houseOne to the first array position in the road.

Mark scheme 33(d)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 4 marks:

  • Creating a new instance of house with identifier

houseOne
  • …with the correct parameters

  • Creating a new instance of houseRoad named

limeAvenue
  • …sending houseOne as parameter to the constructor

e.g.

houseOne = new house(2, 8, 10, 3, 2)
limeAvenue = new houseRoad(houseOne)
out of 4

Question 34

1 mark

34 1 mark

Identify one situation where a linear search is more appropriate than a binary search.

Mark scheme 34

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for any example
e.g.

  • Data is not sorted

  • Item you are looking for is the first item in the list

  • Small number of items

out of 1

Question 35

7 marks

35(a) 5 marks

A one dimensional array holds data that needs to be sorted.

Describe how a quicksort would sort data into ascending order.

Mark scheme 35(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet, each must be applied correctly to data

  • Choose a pivot / identify start and end pointers

  • Compare each element to the pivot… / compare start and end pointers

  • Put items < pivot in the left sublist

  • Put items > pivot in the right sublist

  • Choose a pivot in each sublist

  • If start pointer is larger than end pointer…

  • …then swap data items around

  • And repeat the process until each item becomes a pivot

out of 5

35(b) 2 marks

Explain why a quicksort is known as a divide and conquer algorithm.

Mark scheme 35(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 2

  • decomposing data sets into smaller subsets

  • and then sorting each split subset

  • until each subset is sorted

  • and then combining the subsets to provide a solution

out of 2

Question 36

6 marks

36 6 marks

A breadth-first traversal can be performed on both a tree and a graph.

Show how a breadth-first traversal is performed on the following binary tree.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    M["M"] --- E["E"]
    M --- S["S"]
    E --- C["C"]
    E --- J["J"]
    S --- P["P"]
    S --- V["V"]
    J --- G["G"]
    J --- K["K"]
    K --- L["L"]
Mark scheme 36

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 6

  • Visit root node M

  • Visit E and S

  • Visit C and J (from E)

  • …then P and V (from S)

  • Visit G and K (from J)

  • Visit L (from K)

out of 6

Question 37

13 marks

37(a)

The pseudocode function binarySearch() performs a binary search on the array dataArray that is passed as a parameter. The function returns the array index of searchValue within the array, and -1 if it is not in the array.

The pseudocode binary search algorithm is incomplete.

37(a)(i) 6 marks

Complete the algorithm by filling in the missing statements.

function binarySearch(dataArray:byref, upperbound, lowerbound, ……)
  while true
   middle = lowerbound + ((upperbound – lowerbound) ……)
   if upperbound < lowerbound then
    return ……
   else
    if dataArray[middle] < searchValue then
     lowerbound = ……
    elseif dataArray[middle] > searchValue then
     upperbound = ……
    else
     return ……
    endif
   endif
  endwhile
endfunction
Mark scheme 37(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each number/statement up to a maximum of 6 marks:

function binarySearch(dataArray:byref,
upperbound, lowerbound, searchValue)
  while true
   middle = lowerbound +)
   ((upperbound – lowerbound))
   DIV 2)
   if upperbound < lowerbound
   then
    return -1
   else
    if dataArray[middle] <
    searchValue then
     lowerbound = middle + 1
    elseif dataArray[middle] >
    searchValue then
     upperbound = middle - 1
    else
     return middle
    endif
   endif
  endwhile
endfunction
out of 6

37(a)(ii) 1 mark

The algorithm uses a while loop.

State a different type of loop that could be used instead of the while loop in the given algorithm.

Mark scheme 37(a)(ii)

Do…until / repeat…until / post condition

37(b) 6 marks

The tables below show possible Big O complexities for the worst-case space, best-case space and average time for search algorithms.

Tick the worst-case space complexity for a binary and linear search.

Binary searchLinear search
O(log(n))
O(1)
O(n)

Tick the best-case space complexity for a binary and linear search.

Binary searchLinear search
O(log(n))
O(1)
O(n)

Tick the average time complexity for a binary and linear search.

Binary searchLinear search
O(log(n))
O(1)
O(n)
Mark scheme 37(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for each tick up to a maximum of 6 marks
Worst-case space complexity:

Binary searchLinear search
O(log(n))
O(1)✓✓
O(n)

Best-case space complexity:

Binary searchLinear search
O(log(n))
O(1)✓✓
O(n)

Average time complexity:

Binary searchLinear search
O(log(n))✓
O(1)

O(n) ✓

out of 6

Question 38

10 marks

38

Some of the characters in a game will move and interact independently. Taylor is going to use graphs to plan the movements that each character can take within the game.

DancerGold is one character. The graph shown in Fig. 1 shows the possible movements that DancerGold can make.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["90"] ---|21| B["80"]
    A ---|42| C["65"]
    B ---|40| E["50"]
    B ---|38| D["50"]
    C ---|12| D
    D ---|23| F["30"]
    E ---|55| G["0"]
    F ---|33| G

Fig. 1

DancerGold’s starting state is represented by node A. DancerGold can take any of the paths to reach the end state represented by node G.

The number on each path represents the number of seconds each movement takes.

The number in bold below each node is the heuristic value from A.

38(i) 2 marks

Define the term heuristic in relation to the A* algorithm.

Mark scheme 38(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 2
e.g:

  • A rule of thumb / estimate / guess

  • That estimates the distance / cost from each node to the destination node

  • To speed up the process of finding a solution

  • …by identify which paths to follow first

out of 2

38(ii) 8 marks

Perform an A* algorithm on the graph shown in Fig. 1 to find the shortest path from the starting node to the end node. Show your working, the nodes visited and the distance. You may choose to use the table below to give your answer.

NodeDistance travelledHeuristicDistance travelled + HeuristicPrevious node

Final path:

Distance:

Mark scheme 38(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

NodeDistance travelledHeuristicDistance travelled + HeuristicPrevious nodeMARKING GUIDANCE
A (✓)090901 MARK
B (✓)∞ 2180101A1 MARK
C (✓)∞ 4265107A1 MARK
D (✓)∞ 42+12=5450104C1 MARK
E∞ 21+40=6150111B1 MARK
F (✓)∞ 42+12+23=7730107D1 MARK
G∞ 42+12+23+33=1100110F1 MARK

Final path = A,C,D,F,G and Distance = 110 (1 Mark)

out of 8

Question 39

15 marks

39(a) 9 marks

The following pseudocode procedure performs an insertion sort on the array parameter.

01 procedure insertionSort(dataArray:byRef)
02  for i = 1 to dataArray.Length - 1
03    temp = dataArray[i]
04    tempPos = i – 1
05    exit = false
06    while tempPos >= 0 and exit == false
07      if dataArray[tempPos] < temp then
08        dataArray[tempPos + 1] = dataArray[tempPos]
09        tempPos = tempPos - 1
10      else
11        exit = true
12      endif
13    endwhile
14    dataArray[tempPos + 1] = temp
15  next i
16 endprocedure

* Two sorting algorithms are merge sort and quick sort.

Compare the use of merge sort, quick sort and insertion sort on an array with a small number of elements, and on an array with a very large number of elements.

You should make reference to the time complexities of each algorithm using the Big O notation in your answer.

Mark scheme 39(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level (7-9 marks)
The candidate demonstrates a thorough knowledge and understanding of big O and sorting algorithms; the material is

generally accurate and detailed.
The candidate is able to apply their knowledge and understanding directly and consistently to the context provided.
Evidence/examples will be explicitly relevant to the explanation.
The candidate is able to weigh up the use of the sorting algorithms which results in a supported and realistic judgment as to whether it is possible to use them in this context.
There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level (4-6 marks)
The candidate demonstrates reasonable knoledge and understanding of big O and sorting algorithms; the material is generally accurate but at times underdeveloped.
The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation. The candidate makes a reasonable attempt to come to a conclusion showing some recognition of influencing factors that would determine whether it is possible to use the sorting algorithms in this context.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence

Mark Band 1 – Low Level (1-3 marks)
The candidate demonstrates a basic knowledge of big O and sorting algorithms with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and understanding to the context provided. The candidate provides nothing more than an unsupported assertion.
The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 marks
No attempt to answer the question or response is not worthy of credit.

Guidance

AO1: Knowledge and Understanding

Indicative content O(1)

  • Constant space, does not change

O(n)

  • Linear
  • Same as number of elements
  • As number of elements increases so does the time/space

O(n2)

  • polynominal
  • As number of elements increases, time/space increases by *n

O(n log(n))

  • Linearithmic

AO2: Application

  • Space: Merge sort will require more memory usage as the number of elements increases. Insertion will not require any more space than original. Quick will increase but not as much as merge.
  • Best time: Insertion increases at the same rate as the number of elements. Quick and merge increase at greater rate
  • Worst time: insertion and quick

increase significantly by n for each additional item. Merge sort increases less per element.

  • Log more appropriate for large number of elements

AO3: Evaluation e.g.

  • Small array – space is not important. Few number of elements. Look for consistency.
  • Large array therefore memory important – could remove merge as inappropriate. Logarithmic more efficient.
out of 9

39(b) 6 marks

Describe how a bubble sort will sort an array of 10 elements.

Mark scheme 39(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet for description to max 6

  • Compare each pair of adjacent elements

  • If they are not in the correct order then swap the elements

  • If they are in the correct order then do no swap elements

  • When you read the end of the array return to the start

  • Repeat n elements time

  • Set a flag to be false whenever a swap is made

  • …repeat the loop if the flag is not false

out of 6

Question 40

10 marks

40(a)

Kira is creating a computer game where the user can play against the computer.

In each turn, each character can make one move from a selection of possible moves.

Kira uses a tree data structure shown in Fig. 1 to identify the range of possible moves the computer can make from starting position A. Each connection is a move, with each node representing the result of the move.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["A"] ---|left| B["B"]
    A ---|middle| C["C"]
    A ---|right| E["E"]
    B ---|left| D["D"]
    D ---|left| I["I"]
    C ---|left| F["F"]
    C ---|right| G["G"]
    G ---|left| J["J"]
    E ---|left| H["H"]

Fig. 1

Kira wants to make some changes to the data that is stored in the tree structure shown in Fig. 1.

40(a)(i) 3 marks

The move represented by node ‘E’ needs to be deleted.

Describe the steps an algorithm will follow to delete node ‘E’ from the tree.

Mark scheme 40(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 3

  • Search the tree to find the location of Node E / by example of search

  • Replace the content of node E with blank/null/equivalent

  • Make node A point to the node H

  • Add node E to the empty node list

out of 3

40(a)(ii) 3 marks

The move represented by the node ‘K’ needs to be added. Node ‘K’ needs to be joined to node ‘G.’

Describe the steps the algorithm will follow to add node ‘K’ to the right of node ‘G’.

Mark scheme 40(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 3

  • Search the tree to find the location of node G / by example of search

  • Create a new node with value K

  • Add a pointer from node G to the new node

  • Make node K point to null/equivalent

out of 3

40(b) 4 marks

Kira could have used a graph data structure to represent the moves in her game.

Give two similarities and two differences between a tree and a graph data structure.

Similarity 1

Similarity 2

Difference 1

Difference 2

Mark scheme 40(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per similarity to max 2

  • Both consists of nodes

  • Both are connected by edges/links

  • Both are non-linear data structures

  • Both are dynamic data structures

1 mark per difference to max 2

  • Tree is 1-directional whereas a graph is 2-directional

  • Tree has a root node whereas a graph does not have a (clear) root node

  • Tree will not have cycles whereas graphs can contain cycles

  • Tree will not be weighted whereas edges in a graph can be weighted

out of 4

Question 41

16 marks

41(a) 5 marks

Hugh has written a recursive function called thisFunction() using pseudocode.

01 function thisFunction(theArray, num1, num2, num3)
02  result = num1 + ((num2 - num1) DIV 2)
03  if num2 < num1 then
04    return -1
05  else
06    if theArray[result] < num3 then
07      return thisFunction(theArray, result + 1, num2, num3)
08    elseif theArray[result] > num3 then
09      return thisFunction(theArray, num1, result - 1, num3)
10    else
11      return result
12    endif
13  endif
14 endfunction

The function DIV calculates integer division, e.g. 5 DIV 3 = 1

theArray has the following data:

Index:01234567
Data:510152025303540

Trace the algorithm, and give the final return value, when it is called with the following statement:

thisFunction(theArray, 0, 7, 35)

You may choose to use the table below to give your answer.

Function callnum1num2num3result
thisFunction(theArray,0,7,35)

Final return value ……

Mark scheme 41(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • Calculation of result to 3

  • Call with thisFunction(theArray, num1=4,

num2=7, num3=35)
  • Result = 5

  • call with

thisFunction(theArray,num1=6,num2=7,num
3=35)
  • (Result = 6) return of value 6

Function call num1 num2 num3 result

thisFunction

0 7 35 3

(theArray,0,7,35)
thisFunction

4 7 35 5

(theArray,4,7,35)
thisFunction

6 7 35 6

(thisArray,6,7,35)

Function call

num1

num2

num3

result

thisFunction
(theArray,0,7,35)
thisFunction
(theArray,4,7,35)
thisFunction
(thisArray,6,7,35)

Guidance

7

35

3

7

35

5

7

35

6

out of 5

41(b) 1 mark

State the name of the standard algorithm thisFunction() performs.

Mark scheme 41(b)

Binary search

41(c) 4 marks

Hugh could have written thisFunction() using iteration instead of recursion.

Compare two differences between recursion and iteration.

1

2

Mark scheme 41(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 4, e.g.

  • Recursion uses more memory…

  • …iteration uses less memory

  • Recursion declares new variables /variables are put onto the stack each time…

  • …iteration reuses the same variables

  • Recursive can run out of memory/stack space…

  • …while iteration cannot run out of memory

  • Recursion can express a problem more elegantly / in fewer lines of code…

  • …while iteration can take more lines of code / be harder to understand

  • Recursion will be self-referential / will call itself…

  • … whereas iteration does not

out of 4

41(d) 6 marks

The recursive function thisFunction() is printed again here for your reference.

01 function thisFunction(theArray, num1, num2, num3)
02  result = num1 + ((num2 - num1) DIV 2)
03  if num2 < num1 then
04    return -1
05  else
06    if theArray[result] < num3 then
07      return thisFunction(theArray, result + 1, num2, num3)
08    elseif theArray[result] > num3 then
09      return thisFunction(theArray, num1, result - 1, num3)
10    else
11      return result
12    endif
13  endif
14 endfunction

Rewrite the function thisFunction() so that it uses iteration instead of recursion.

You should write your answer using pseudocode or program code.

Mark scheme 41(d)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet to max 6

  • Retains function call

  • Uses a loop

  • …that will loop until all elements inspected or value found

  • Updates num1 appropriately

  • Updates num2 appropriately

  • Returns -1 in the correct place if the value has not been found

  • Returns the result in the correct place if the value has been found

e.g.

function thisFunction(theArray, num1, num2, num3)
while (true)
  result = num1 + ((num2 - num1) DIV 2)
  if num2 < num1 then
   return -1
  else
   if theArray[result] < num3 then
    num1 = result + 1
   elseif theArray[result] > num3 then
    num2 = result - 1
   else
    return result
   endif
  endif
endwhile
endfunction
out of 6

Question 42

6 marks

42(a) 1 mark

Kira is creating a computer game where the user can play against the computer.

In each turn, each character can make one move from a selection of possible moves.

Kira uses a tree data structure shown in Fig. 1 to identify the range of possible moves the computer can make from starting position A. Each connection is a move, with each node representing the result of the move.

[Diagram redrawn from the original paper by an AI model (Gemma 4 12B). It may contain mistakes.]

flowchart TD
    A["A"] ---|left| B["B"]
    A ---|middle| C["C"]
    A ---|right| E["E"]
    B ---|left| D["D"]
    D ---|left| I["I"]
    C ---|left| F["F"]
    C ---|right| G["G"]
    G ---|left| J["J"]
    E ---|left| H["H"]

Fig. 1

State why the tree shown in Fig. 1 is not an example of a binary search tree.

Mark scheme 42(a)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

One node (node A) has more than 2 connections
Nodes aren’t ordered (e.g. F is C’s left child)

out of 1

42(b) 1 mark

State what type of pointers are used to store nodes I, F, J and H so they do not point to any other nodes.

Mark scheme 42(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark for identification

  • Null pointers

out of 1

42(c) 4 marks

Kira wants the program to traverse the tree to evaluate the range of possible moves. She is considering using a breadth-first traversal or a depth-first (post-order) traversal.

Show how a breadth-first traversal would traverse the tree shown in Fig. 1.

Mark scheme 42(c)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet

  • Take A as starting node

  • Visit B, C and E

  • Visit D, F, G and H

  • Visit I and J

Guidance

Allow the reverse ordering from right to left e.g. A; E, C, B; H, G, F, D; J, I

out of 4

Question 43

11 marks

43(a) 1 mark

Poppy would like to use a bubble sort to sort 250 000 numbers into order from lowest to highest.

Currently the first five numbers before they have been sorted are:

195 584167 147158 187160 125184 236

Currently the last five numbers before they have been sorted are:

105819 558191520 21515

State the name of one other sorting algorithm that Poppy could have used.

Mark scheme 43(a)
  • Insertion sort

1 A02.1 (1)

Guidance

Allow other sorting algorithms not listed in the specification (e.g. Merge Sort, Quick Sort etc)

43(b) 9 marks

* Discuss how a bubble sort works and how efficient it will be when sorting these 250 000 items into order from lowest to highest.

Mark scheme 43(b)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

Mark Band 3 – High level (7-9 marks)
The candidate demonstrates a thorough knowledge and understanding of bubble sorts; the material is generally accurate and detailed. The candidate is able to apply their knowledge and understanding directly and consistently to the context provided. Evidence/examples will be explicitly relevant to the explanation. The candidate is able to weigh up the use of bubble sorts within the context which results in a supported and realistic judgment as to whether it is suitable to use within the context.There is a well-developed line of reasoning which is clear and logically structured. The information presented is relevant and substantiated.

Mark Band 2 – Mid level (4-6 marks)
The candidate demonstrates reasonable knowledge and understanding of bubble sorts; the material is generally accurate but at times underdeveloped.The candidate is able to apply their knowledge and understanding directly to the context provided although one or two opportunities are missed. Evidence/examples are for the most part implicitly relevant to the explanation.
The candidate makes a reasonable attempt to come to a conclusion showing some recognition of influencing factors that would determine whether it is possible to use bubble sorts in this context.
There is a line of reasoning presented with some structure. The information presented is in the most part relevant and supported by some evidence

Mark Band 1 – Low Level (1-3 marks)
The candidate demonstrates a basic knowledge of bubble sorts with limited understanding shown; the material is basic and contains some inaccuracies. The candidates makes a limited attempt to apply acquired knowledge and
understanding to the context provided. The candidate

provides nothing more than an unsupported assertion.The information is basic and comunicated in an unstructured way. The information is supported by limited evidence and the relationship to the evidence may not be clear.

0 marks
No attempt to answer the question or response is not worthy of credit.

Guidance

Knowledge and Understanding

  • All adjacent items are compared against each other.
  • The biggest number in the adjacent pair is swapped over with the smallest number. A temp variable is used to hold the data while it’s being moved.
  • When a swap is made a flag is set.
  • This is repeated for all adjacent values, known as one pass.
  • At the end of one pass, the largest item should appear at the end of the list.
  • If at the end of the list the flag has been set the flag is unset and the algorithm starts from the beginning of the list again.
  • When the algorithm gets to the end of

the list and the flag is unset the list is sorted.

Application

  • As there are 250,000 items a bubble sort would perform very slowly as a lot of passes will need to be made in order to sort the items.
  • Bubble sorts are better suited to data sets where the items are almost/partly sorted. However the smaller numbers are currently towards the end and the larger numbers are towards the start.
  • This will therefore increase the amount of comparisons / passes/swaps required which will therefore slow the performance of the sort down.

Evaluation

  • The algorithm is easy to implement as the number of lines of code is less than other standard sorting algorithms.
  • Although a bubble sort will be able to sort the items into order, it will take longer than other sorting algorithms due to the number of items and the current order or

items in the unsorted list.

out of 9

43(c) 1 mark

State the number of comparisons that will need to be made in the first pass of the bubble sort.

Mark scheme 43(c)
  • 249,999

1 A02.2 (1)

Question 44

15 marks

44(a)

Oscar owns a taxi company. He would like a program to handle taxi bookings from customers.

When a customer makes a booking, they are placed into a queue data structure until a taxi driver is available.

44(a)(i) 4 marks

Explain why Oscar uses a queue data structure rather than a stack data structure.

Mark scheme 44(a)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 4 marks:

  • A queue is First In First Out (FIFO)

  • Therefore bookings will be executed in the order they have received

  • A stack is Last In First Out (LIFO)

  • Therefore the bookings would be executed from the most recent booking

4

A02.2 (4)

out of 4

44(a)(ii) 1 mark

Oscar has written a procedure, enqueue, to be able to add a customer number to the queue. The queue is not circular.

01   procedure enqueue(custNumber)
02    maxElements = 10
03    if (tail + 1) > maxElements then
04      print ("Error, queue is full")
05    else
06      head = head + 1
07      queue[head] = custNumber
08    endif
09   endprocedure

State the name of the parameter used in the procedure enqueue.

Mark scheme 44(a)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

custNumber

1

A03.3 (1)

out of 1

44(a)(iii) 2 marks

The procedure enqueue contains an error on line 06 and line 07.

Rewrite lines 06 and 07 of the procedure enqueue so that the queue works correctly.

Mark scheme 44(a)(iii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 2 marks:

  • Correct logic for incrementing the tail pointer by 1 (e.g. tail = tail +1)

  • Correct logic for adding custNumber to the tail pointer (e.g. queue[tail]=custNumber)

2

A03.2 (2)

out of 2

44(a)(iv) 1 mark

Identify the logical condition in the procedure enqueue that affects whether a new Item can be added to the queue.

Mark scheme 44(a)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

  • If the tail is greater than 10 / maxElements

1

A02.2 (1)

Guidance

Accept:

not((tail + 1) >
maxElements)

Or

(tail + 1) <=
maxElements

Or equivalent

out of 1

44(b)

Some of Oscar’s customers are rated as gold. Customers who are rated as gold are given priority when they make a taxi booking. Some customers rated as gold are shown here.

ArshadBettyDaveFreddieHarryJimmyKanwalLynnSiadTommyWill

When a customer makes a booking, Oscar will make use of a binary search to check if they are gold rated.

Oscar would like to know if ‘Tommy’ is gold rated.

44(b)(i) 3 marks

State the three values that will be set as the midpoints and then checked against ‘Tommy’ on each iteration of the binary search.

Show your working here.

Midpoint 1

Midpoint 2

Midpoint 3

Mark scheme 44(b)(i)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 3 marks:

  • 5 (Jimmy)

  • 8 (Siad)

  • 9 (Tommy)

3

A02.1 (3)

out of 3

44(b)(ii) 2 marks

Oscar has 75 000 customers stored in his program.

Describe the benefit to Oscar of using binary searches in his program.

Benefit

Mark scheme 44(b)(ii)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

1 mark per bullet up to a maximum of 2 marks, e.g:

  • Efficient

  • ...as does not need to search every single element/uses divide and conquer

2

A01.2 (2)

out of 2

44(b)(iii) 1 mark

State one other search algorithm that Oscar could have used.

Mark scheme 44(b)(iii)
  • Linear Search / Serial Search

A02.1 (1)

44(b)(iv) 1 mark

State the pre-condition which has been met, which meant that Oscar did not need to use the search algorithm you stated in the part above.

END OF QUESTION PAPER

Mark scheme 44(b)(iv)

Tick each point your answer makes. Your mark is worked out from your ticks, and you can change it.

  • The items are in alphabetical order / the items are sorted

1

A02.1 (1)

out of 1