A Level Computer Science 9618 Paper 41, May/June 2025

Question paper and mark scheme75 marks3 questions

Solve it on ExamPal

Practise

Untimed. Write on the paper and check as you go.

Start

Exam

Timed, with a clock you set, like sitting the real paper.

Start

Opens full screen.

Opening the question paper

Read as textThe questions and the mark scheme as plain text. Easier to read on a phone.

Question paper

9618/41 · May/June 2025

Download PDF
1

A program stores positive integers in a circular queue. The queue is stored as a global 1D array of 20 integers with the identifier Queue. Each index is initialised with the data –1 The global variable HeadPointer, initialised to –1, points to the first element in the queue. The global variable TailPointer, initialised to –1, points to the last element in the queue. The global variable NumberItems, initialised to 0, stores the number of items in the queue.

a

Write program code to declare and initialise Queue, HeadPointer, TailPointer and NumberItems Save your program as Question1_J25. Copy and paste the program code into part 1(a) in the evidence document.

[2]
b

The function Enqueue(): • takes an integer as a parameter • checks if the queue is full • returns FALSE if the queue is full • stores the parameter in the next position in the queue and returns TRUE if the queue is not full • updates the appropriate pointers and NumberItems Write program code for Enqueue() Save your program. Copy and paste the program code into part 1(b) in the evidence document.

[6]
c

The main program: • attempts to store each of the integers 1 to 25 (inclusive) in the queue in ascending numerical order using Enqueue() • outputs the integer that was passed to Enqueue() and "Successful" if it was stored in the queue, or "Unsuccessful" if it was not stored in the queue. For example:  if the integer 5 is passed to Enqueue() and is stored in the queue, the output will be: "5 Successful"  if the integer 23 is passed to Enqueue() and is not stored in the queue, the output will be: "23 Unsuccessful" Write program code for the main program. Save your program. Copy and paste the program code into part 1(c) in the evidence document.

[3]
d

The function Dequeue() returns –1 if the queue is empty. If the queue is not empty, the function returns the next item in the queue, updates the appropriate pointers and updates NumberItems Write program code for Dequeue() Save your program. Copy and paste the program code into part 1(d) in the evidence document.

[6]
e(i)

Write program code to extend the main program to call Dequeue() twice and output the return value each time. Save your program. Copy and paste the program code into part 1(e)(i) in the evidence document.

[2]
e(ii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 1(e)(ii) in the evidence document.

[1]
2

A program reads data from a text file, splits the data depending on its content and stores the separated data into different files. The text file TheData.txt contains 72 lines of data. Each line of data has an integer number and a string colour that are separated by a comma. For example, the first line in the file is: 10,red The integer is 10 and the string is "red" The file contains six different colours: red, green, blue, orange, yellow, pink.

a

The function ReadData(): • prompts the user to enter a filename and reads this filename from the user • opens the file and reads each line of data into a 1D array • returns the populated 1D array. The function needs to work for a file that contains an unknown number of lines. Write program code for ReadData() Save your program as Question2_J25. Copy and paste the program code into part 2(a) in the evidence document.

[7]
b

The procedure SplitData() takes a 1D string array as a parameter with the identifier DataArray The procedure declares six 1D arrays: one array for each colour that appears in the file (red, green, blue, orange, yellow, pink). The procedure accesses each string in DataArray. The data in each string is split into the integer and the colour. The integer is stored in the array that matches the colour. For example, the first string in DataArray has the integer 10 and the colour red, so the integer 10 is stored in the array for the colour red. Write program code for SplitData() Save your program. Copy and paste the program code into part 2(b) in the evidence document.

[6]
c

The procedure StoreData(): • takes two parameters: a 1D array DataToStore and a filename • opens the text file with the filename that is passed as a parameter • appends each item of data from DataToStore to a new line in the text file • uses exception handling when opening and writing data to the text file. Write program code for StoreData() Save your program. Copy and paste the program code into part 2(c) in the evidence document.

[5]
d

Each of the six colours has a blank text file where the numbers will be stored. The names of these six text files are: • Blue.txt • Green.txt • Orange.txt • Pink.txt • Red.txt • Yellow.txt The procedure SplitData() needs amending to call StoreData() six times, with each of the six colour arrays and the name of the text file that corresponds to that colour. For example, StoreData() will be called with the red array and the file name "Red.txt" Write program code to amend SplitData() Save your program. Copy and paste the program code into part 2(d) in the evidence document.

[2]
e(i)

The main program calls ReadData() and then SplitData() Write program code for the main program. Save your program. Copy and paste the program code into part 2(e)(i) in the evidence document.

[3]
e(ii)

Test your program. Input the text "TheData.txt" when prompted. Take a screenshot of the output(s) and a screenshot showing the content of the file that stores the red numbers. Save your program. Copy and paste the screenshot(s) into part 2(e)(ii) in the evidence document.

[2]
3

A program stores data in a binary tree that is designed using Object-Oriented Programming (OOP). The tree stores data in ascending numerical order, for example: 30 20 45 1 21 33 63 The class Node stores data about the nodes. Node NodeData : Integer | stores the node's integer data LeftNode : Node | stores the node that is stored to the left of the current node, or a null value if there is no node to the left RightNode : Node | stores the node that is stored to the right of the current node, or a null value if there is no node to the right Constructor() | initialises NodeData to its parameter value; initialises LeftNode and RightNode to a null value GetLeft() | returns LeftNode GetRight() | returns RightNode GetData() | returns NodeData SetLeft() | takes an object of type Node as a parameter and stores it in LeftNode SetRight() | takes an object of type Node as a parameter and stores it in RightNode

a(i)

Write program code to declare the class Node and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program as Question3_J25. Copy and paste the program code into part 3(a)(i) in the evidence document.

[4]
a(ii)

Write program code for the three get methods. Save your program. Copy and paste the program code into part 3(a)(ii) in the evidence document.

[3]
a(iii)

The method SetLeft() takes an object of type Node as a parameter. The method stores the parameter in the attribute LeftNode The method SetRight() takes an object of type Node as a parameter. The method stores the parameter in the attribute RightNode Write program code for SetLeft() and SetRight() Save your program. Copy and paste the program code into part 3(a)(iii) in the evidence document.

[3]
b

Write the main program to declare five objects of type Node : • Node 1 with the data 10 • Node 2 with the data 20 • Node 3 with the data 5 • Node 4 with the data 15 • Node 5 with the data 7 Save your program. Copy and paste the program code into part 3(b) in the evidence document.

[2]
c(i)

The class Tree stores the tree. Tree FirstNode : Node | stores the root node in the tree Constructor() | initialises FirstNode to its parameter value GetRootNode() | returns the node stored in FirstNode Insert() | stores its parameter node in the correct position in the tree Write program code to declare the class Tree and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program. Copy and paste the program code into part 3(c)(i) in the evidence document.

[2]
c(ii)

Write program code for GetRootNode() Save your program. Copy and paste the program code into part 3(c)(ii) in the evidence document.

[1]
c(iii)

The method Insert() takes a node as a parameter and then searches the tree to find the position to insert the new node by: • checking whether the node’s data is less than or greater than the root node’s data • moving to the left node if the data is less than the root node’s data • moving to the right node if the data is greater than or equal to the root node’s data • repeating until the final position of the node is found and stores the node in that position. Write program code for Insert() Save your program. Copy and paste the program code into part 3(c)(iii) in the evidence document.

[6]
d

The recursive procedure OutputInOrder() outputs the data stored in the binary tree in ascending numerical order. The procedure takes a Node object as a parameter and then: • checks if the left node is null. If there is a left node, the function calls itself with the left node • outputs the data of the current node • checks if the right node is null. If there is a right node, the function calls itself with the right node. Write program code for OutputInOrder() Save your program. Copy and paste the program code into part 3(d) in the evidence document.

[5]
e(i)

Write program code to extend the main program to: • create a new object of type Tree with the node containing the data 10 as the first node • insert the nodes with the values 20, 5, 15 and 7 into the tree in the order given • call OutputInOrder() with the tree’s root node as a parameter. Save your program. Copy and paste the program code into part 3(e)(i) in the evidence document.

[3]
e(ii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 3(e)(ii) in the evidence document.

[1]

Mark scheme

9618/41 · May/June 2025

Download PDF

1a · 2 marks

  • 1 mark

    (global) Declaration of 1D array Queue, 20 elements initialised with –1

  • 1 mark

    (global) HeadPointer and TailPointer initialised to –1, NumberItems initialised with 0

1b · 6 marks

  • 1 mark

    Function header (and close) taking 1 (integer) parameter and returning a Boolean value in all cases

  • 1 mark

    Checking if queue is full (NumberItems = 20) and returning FALSE

  • 1 mark

    Checking if queue is empty (NumberItems = 0) then and updating TailPointer and HeadPointer appropriately

  • 1 mark

    Incrementing TailPointer and NumberItems in appropriate place …

  • 1 mark

    … looping back to 0 for TailPointer if at end of structure

  • 1 mark

    Storing parameter in Queue[TailPointer] (after increment) and returning TRUE

1c · 3 marks

  • 1 mark

    Calling Enqueue() with 1 to 25 (inclusive) in order

  • 2 marks

    … storing/using return value in selection …outputting Successful with integer and outputting Unsuccessful with integer correctly

1d · 6 marks

  • 1 mark

    Dequeue() header (and close) and checking if queue is empty (NumberItems = 0) and returning –1

  • 1 mark

    Returning data at HeadPointer

  • 1 mark

    Incrementing HeadPointer …

  • 1 mark

    … and catching if = 20 to return to 0

  • 1 mark

    Decrementing NumberItems

  • 1 mark

    Resetting HeadPointer and TailPointer when queue is empty

1e(i) · 2 marks

  • 1 mark

    Calling Dequeue() twice

  • 1 mark

    … outputting return value from both calls

1e(ii) · 1 mark

  • 1 mark

    1 to 20 with Successful 21 to 25 with Unsuccessful 1 and 2 output

2a · 7 marks

  • 1 mark

    Function header (and end)

  • 1 mark

    Prompt to enter filename and reading input

  • 1 mark

    Opening the file (to read) and closing the file in an appropriate place

  • 1 mark

    Looping until EOF …

  • 1 mark

    … reading each line in the file …

  • 1 mark

    … (removing line break and) inserting in array

  • 1 mark

    Returning populated array

  • 1 mark

    Exception handling try catch with appropriate output

2b · 6 marks

  • 1 mark

    Procedure header (and end) taking (1D array) DataArray (of strings) as a parameter

  • 1 mark

    Declaration/use of 6 1D arrays (equivalent), one for each colour

  • 1 mark

    Looping through each line in parameter DataArray …

  • 1 mark

    … splitting by comma

  • 1 mark

    Comparing 2nd value/colour to each colour to select array …

  • 1 mark

    … storing 1st value/integer in correct array

2c · 5 marks

  • 1 mark

    Procedure header taking (1D) array and filename as parameters, opening file to append and closing file (in appropriate place)

  • 1 mark

    Looping through each item in array parameter …

  • 1 mark

    … writing to the file

  • 1 mark

    … with new line break between each line

  • 1 mark

    Using exception handling try and catch with suitable output

2d · 2 marks

  • 1 mark

    Calling StoreData with one array and filename

  • 1 mark

    Calling StoreData with remaining 5 arrays and filename

2e(i) · 3 marks

  • 1 mark

    Calling ReadData() …

  • 1 mark

    … and storing/using return value

  • 1 mark

    Calling SplitData() with returned array as a parameter

2e(ii) · 2 marks

  • 1 mark

    Prompt and input of filename TheData.txt

  • 1 mark

    Screenshot of data in red file. Filename must be shown in same screenshot as data

3a(i) · 4 marks

  • 1 mark

    Class header (and end where appropriate)

  • 1 mark

    Constructor header (and end where appropriate) with (min) one parameter (integer) within class

  • 1 mark

    3 attributes with correct data types

  • 1 mark

    NodeData has parameter assigned, LeftNode and RightNode are assigned null within constructor

3a(ii) · 3 marks

  • 1 mark

    1 get method with no parameter …

  • 1 mark

    … returning correct value

  • 1 mark

    2nd and 3rd correct get methods

3a(iii) · 3 marks

  • 1 mark

    1 set method taking parameter of type Node …

  • 1 mark

    … assigning to correct attribute

  • 1 mark

    2nd correct set method

3b · 2 marks

  • 1 mark

    Creating 1 instance of Node with a correct value and storing the node …

  • 1 mark

    … remaining 4 correct

3c(i) · 2 marks

  • 1 mark

    Class Tree header (and end) no inheritance and constructor header (and end) taking 1 node parameter within class …

  • 1 mark

    … storing parameter in FirstNode declared as a Node data type

3c(ii) · 1 mark

  • 1 mark

    Get method header (and end) with no parameter, returning FirstNode

3c(iii) · 6 marks

  • 1 mark

    Insert method header (and end) taking 1 node parameter

  • 1 mark

    If parameter < first node, checking if there is a left node …

  • 1 mark

    … storing node in left node if it is null

  • 1 mark

    If parameter >= first node, checking if there is a right node …

  • 1 mark

    … storing node in right node if it is null

  • 1 mark

    Looping until correct position is found // recursive calls

3d · 5 marks

  • 1 mark

    Procedure header (and end) taking node as parameter, that is recursive

  • 1 mark

    Checking if left is null and recursive call if not null

  • 1 mark

    Outputting node's data

  • 1 mark

    Checking if right is null and recursive call if not null

  • 1 mark

    Correct order

3e(i) · 3 marks

  • 1 mark

    Creation of Tree object with the Node with value 10 as parameter

  • 1 mark

    Calling method Insert() for tree with the nodes for 20, 5, 15 and 7 in order

  • 1 mark

    Calling OutputInOrder() with tree's root node as parameter

3e(ii) · 1 mark

  • 1 mark

    Output of 5 7 10 15 20

Questions

  1. 1
    Question 120 marks
    Mark scheme ›
  2. 2
    Question 225 marks
    Mark scheme ›
  3. 3
    Question 330 marks
    Mark scheme ›

More 9618 papers

Other papers from May/June 2025

Solve it on ExamPalStart