9618/43 · May/June 2025 · Worked solutions

Step-by-step solutions based on the mark scheme (not a mark-scheme dump).

Question 1

Paper page 2 for Q1
Original paper page 2

Part 1(a) — solution

  1. (Global) Queue array with 50 integer elements …
  2. … all initialised to –1
  3. (Global) HeadPointer and TailPointer initialised with –1

Visual Basic (VB.NET)

Dim Queue(49) As Integer
 Dim HeadPointer As Integer
 Dim TailPointer As Integer
 Sub Main(args As String())
    HeadPointer = -1
    TailPointer = -1
    For x = 0 To 49
        Queue(x) = -1
    Next
 End Sub

Python

Queue = [] #integer 50 elements
 HeadPointer = -1
 TailPointer = -1
 #main
 HeadPointer = -1
 TailPointer = -1
 for x in range(50):
      Queue.append(-1)

Mark points

  • (Global) Queue array with 50 integer elements …
  • … all initialised to –1
  • (Global) HeadPointer and TailPointer initialised with –1

Part 1(b) — solution

  1. Function Enqueue() header (and end) taking one (integer) parameter
  2. Checking if Queue is full …
  3. …returning FALSE if full and TRUE if not full
  4. (Otherwise) storing data item at TailPointer + 1 (check incrementing)
  5. Incrementing TailPointer
  6. Checking if this is the first element and incrementing/storing 0 in HeadPointer

Visual Basic (VB.NET)

Function Enqueue(DataValue As Integer)
    If TailPointer < 49 Then
        TailPointer = TailPointer + 1
        Queue(TailPointer) = DataValue
        If HeadPointer = -1 Then
           HeadPointer = 0
        End If
        Return True
    Else
        Return False
    End If
 End Function

 University Press & Assessment 2025                       Page 10 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

def Enqueue(Data):
      global Queue
      global TailPointer
      global HeadPointer

        if TailPointer < 49:
            TailPointer = TailPointer + 1
            Queue[TailPointer] = Data

            if HeadPointer == -1:
                HeadPointer = 0
            return True
        else:
            return False

Mark points

  • Function Enqueue() header (and end) taking one (integer) parameter
  • Checking if Queue is full …
  • …returning FALSE if full and TRUE if not full
  • (Otherwise) storing data item at TailPointer + 1 (check incrementing)
  • Incrementing TailPointer
  • Checking if this is the first element and incrementing/storing 0 in HeadPointer

Part 1(c) — solution

  1. Function Dequeue() header (and close) and returning appropriate value in all cases
  2. Checking if queue is empty …
  3. … and returning –1 if empty
  4. Accessing and returning element at Queue[HeadPointer] (before HeadPointer is incremented)
  5. Incrementing HeadPointer

Visual Basic (VB.NET)

Function Dequeue()
    Dim ReturnValue As Integer
    If HeadPointer > -1 And HeadPointer <= TailPointer Then
        ReturnValue = Queue(HeadPointer)
        HeadPointer = HeadPointer + 1
        Return ReturnValue
    Else
        Return -1
    End If
 End Function

Python

def Dequeue():
      global Queue
      global HeadPointer
      if HeadPointer > -1 and HeadPointer <= TailPointer:
          ReturnValue = Queue[HeadPointer]
          HeadPointer = HeadPointer + 1
          return ReturnValue
      else:
          return -1

Mark points

  • Function Dequeue() header (and close) and returning appropriate value in all cases
  • Checking if queue is empty …
  • … and returning –1 if empty
  • Accessing and returning element at Queue[HeadPointer] (before HeadPointer is incremented)
  • Incrementing HeadPointer

Part 1(d) — solution

  1. CreateQueue() header (and end) and opening the file to read and closing file in appropriate place
  2. Looping until end of file
  3. Reading in each/all lines (and converting to integer and removing new line)
  4. … calling Enqueue() once with each value …
  5. … checking return value and outputting "Queue full" if full (can output once or many times)
  6. Exception try, catch with appropriate output. All file access within try

Visual Basic (VB.NET)

Sub CreateQueue()
    Dim ReturnValue As Boolean
    Dim ReadData As Integer
    Try
        Dim FileReader As New System.IO.StreamReader("QueueData.txt")
        While Not FileReader.EndOfStream
           ReadData = FileReader.ReadLine()
           ReturnValue = Enqueue(ReadData)
           If ReturnValue = False Then
              Console.WriteLine("Queue full")
           End If
        End While
        FileReader.Close()
    Catch ex As Exception
        Console.WriteLine("Cannot open or read file")
    End Try
 End Sub

 University Press & Assessment 2025                       Page 15 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

def CreateQueue():
      try:
          File = open("QueueData.txt")
          for Line in File:
              ReturnValue = Enqueue(int(Line))
              if ReturnValue == False:
                  print("Queue full")
                  break;
          File.close()
      except:
          print("Cannot open or read file")

Mark points

  • CreateQueue() header (and end) and opening the file to read and closing file in appropriate place
  • Looping until end of file
  • Reading in each/all lines (and converting to integer and removing new line)
  • … calling Enqueue() once with each value …
  • … checking return value and outputting "Queue full" if full (can output once or many times)
  • Exception try, catch with appropriate output. All file access within try

Part 1(e)(i) — solution

  1. Calling CreateQueue()
  2. Calling Dequeue() and storing/using return value …
  3. … repeatedly until return value is –1
  4. … adding together all return values to create a total within the loop …
  5. … outputting the total

Visual Basic (VB.NET)

CreateQueue()
 Dim Total As Integer = 0
 Dim ReturnValue As Integer = 0
 While ReturnValue > -1
    ReturnValue = Dequeue()
    If ReturnValue <> -1 Then
        Total = Total + ReturnValue
    End If
 End While
 Console.WriteLine("The total is " & Total)

Python

CreateQueue()
 Total = 0
 ReturnValue = 0

 while ReturnValue > -1:
     ReturnValue = Dequeue()
     if ReturnValue != -1:
         Total = Total + ReturnValue
 print("The total is", Total)

 University Press & Assessment 2025                       Page 17 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Mark points

  • Calling CreateQueue()
  • Calling Dequeue() and storing/using return value …
  • … repeatedly until return value is –1
  • … adding together all return values to create a total within the loop …
  • … outputting the total

Part 1(e)(ii) — solution

1 mark for screenshot showing 3059 1 University Press & Assessment 2025 Page 18 of 45 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2025

Mark points

  • Include the ideas shown in the solution above.

Question 2

Paper page 4 for Q2
Original paper page 4

Part 2(a) — solution

  1. DataArray = [0, 3, 4, 56, 67, 44, 43, 32, 31, 345, 45, 6, 54, 1]
  2. Dim DataArray() As Integer = {0, 3, 4, 56, 67, 44, 43, 32, 31, 345, 45, 6, 54, 1}

Visual Basic (VB.NET)

Dim DataArray() As Integer = {0, 3, 4, 56, 67, 44, 43, 32, 31, 345, 45, 6, 54, 1}

 University Press & Assessment 2025                       Page 19 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme                        May/June 2025

Python

DataArray = [0, 3, 4, 56, 67, 44, 43, 32, 31, 345, 45, 6, 54, 1]

Mark points

  • DataArray = [0, 3, 4, 56, 67, 44, 43, 32, 31, 345, 45, 6, 54, 1]
  • Dim DataArray() As Integer = {0, 3, 4, 56, 67, 44, 43, 32, 31, 345, 45, 6, 54, 1}

Part 2(b) — solution

  1. InsertionSort() header (and close) taking array as a parameter and returning (attempt at) sorted array
  2. Looping through/for each element
  3. Extracting element and comparing to sorted list …
  4. … moving elements in sorted list
  5. … and inserting element in correct position (ascending order)

Visual Basic (VB.NET)

Function InsertionSort(DataArray)
    Dim CurrentValue As Integer
    Dim Y As Integer
    If (DataArray.length()) <= 1 Then
        Return DataArray
    End If
    For X = 1 To DataArray.length() - 1
        CurrentValue = DataArray(X)
        Y = X - 1
        While Y >= 0 AndAlso CurrentValue < DataArray(Y)
           DataArray(Y + 1) = DataArray(Y)
           Y = Y - 1
        End While
        DataArray(Y + 1) = CurrentValue
    Next X
    Return DataArray
 End Function

 University Press & Assessment 2025                       Page 22 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme                May/June 2025

Python

def InsertionSort(DataArray):
      if (len(DataArray)) <= 1:
          return DataArray
      for X in range(1, len(DataArray)):
          CurrentValue = DataArray[X]
          Y = X-1
          while Y >=0 and CurrentValue < DataArray[Y]:
              DataArray[Y+1] = DataArray[Y]
              Y = Y -1
          DataArray[Y+1] = CurrentValue
      return DataArray

Mark points

  • InsertionSort() header (and close) taking array as a parameter and returning (attempt at) sorted array
  • Looping through/for each element
  • Extracting element and comparing to sorted list …
  • … moving elements in sorted list
  • … and inserting element in correct position (ascending order)

Part 2(c) — solution

  1. OutputArray() header (and close) taking an array parameter and outputting the array contents …
  2. … in correct format

Visual Basic (VB.NET)

Sub OutputArray(DataArray)
    Dim Output As String = ""
    Dim X As Integer = 0
    While X < DataArray.length
        If DataArray(X) <> -1 Then
           Output = Output & DataArray(X) & " "
        End If
        X = X + 1
    End While
    Console.WriteLine(Output)
 End Sub

 University Press & Assessment 2025                       Page 24 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

def OutputArray(DataArray):
      Output = ""
      for Item in DataArray:
          Output = Output + str(Item) + " "
      print(Output)

Mark points

  • OutputArray() header (and close) taking an array parameter and outputting the array contents …
  • … in correct format

Part 2(d)(i) — solution

  1. Calling InsertionSort() with array parameter and storing/using return array
  2. … calling OutputArray() with array parameter before and after InsertionSort()

Visual Basic (VB.NET)

OutputArray(DataArray)
 DataArray = InsertionSort(DataArray)
 OutputArray(DataArray)

Python

OutputArray(DataArray)
 DataArray = InsertionSort(DataArray)
 OutputArray(DataArray)

Mark points

  • Calling InsertionSort() with array parameter and storing/using return array
  • … calling OutputArray() with array parameter before and after InsertionSort()

Part 2(d)(ii) — solution

1 mark for output showing unsorted then sorted array 1 e.g. University Press & Assessment 2025 Page 25 of 45 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2025

Mark points

  • Include the ideas shown in the solution above.

Part 2(e) — solution

  1. Search() header (and close) taking array and integer as parameters
  2. Looping/recursive calls until no elements left/Low<=High and returning –1 if not found
  3. … calculating middle index and accessing this value
  4. … comparison of array at middle value to integer parameter
  5. … if they are equal return mid
  6. … if array[mid] < parameter update low to middle + 1, if array[mid] > parameter update high to middle – 1 // recursive

Visual Basic (VB.NET)

Function Search(DataArray, ItemToFind)
    Dim Low As Integer = 0
    Dim High As Integer = DataArray.length() - 1
    Dim Middle As Integer = 0
    While Low <= High
        Middle = (High + Low) \ 2
        If DataArray(Middle) < ItemToFind Then
           Low = Middle + 1
        ElseIf DataArray(Middle) > ItemToFind Then
           High = Middle - 1
        Else
           Return Middle
        End If
    End While
    Return -1
 End Function

 University Press & Assessment 2025                       Page 28 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

def Search(DataArray, ItemToFind):
      Low = 0
      High = len(DataArray) - 1
      Middle = 0

        while Low <= High:
            Middle = (High + Low) // 2
            if DataArray[Middle] < ItemToFind:
                Low = Middle + 1
            elif DataArray[Middle] > ItemToFind:
                High = Middle - 1
            else:
                return Middle
        return -1

Mark points

  • Search() header (and close) taking array and integer as parameters
  • Looping/recursive calls until no elements left/Low<=High and returning –1 if not found
  • … calculating middle index and accessing this value
  • … comparison of array at middle value to integer parameter
  • … if they are equal return mid
  • … if array[mid] < parameter update low to middle + 1, if array[mid] > parameter update high to middle – 1 // recursive

Part 2(f)(i) — solution

  1. Calling Search() with all four sets of values 0 345 67 2
  2. … outputting 'not found' or index in appropriate message each time

Visual Basic (VB.NET)

Dim Location As Integer = Search(DataArray, 0)
 If Location = -1 Then
    Console.WriteLine("Data not found")
 Else
    Console.WriteLine("Data found at " & Location)
 End If

 University Press & Assessment 2025                       Page 31 of 45

9618/43                                           Cambridge International AS & A Level – Mark Scheme   May/June 2025

 Location = Search(DataArray, 345)
 If Location = -1 Then
    Console.WriteLine("Data not found")
 Else
    Console.WriteLine("Data found at " & Location)
 End If
 Location = Search(DataArray, 67)
 If Location = -1 Then
    Console.WriteLine("Data not found")
 Else
    Console.WriteLine("Data found at " & Location)
 End If
 Location = Search(DataArray, 2)
 If Location = -1 Then
    Console.WriteLine("Data not found")
 Else
    Console.WriteLine("Data found at " & Location)
 End If

Python

Location = Search(DataArray, 0)
 if Location == -1:
      print("Data not found")
 else:
      print("Data found at", Location)
 Location = Search(DataArray, 345)
 if Location == -1:
      print("Data not found")
 else:
      print("Data found at", Location)

 Location = Search(DataArray, 67)
 if Location == -1:
     print("Data not found")
 else:
     print("Data found at", Location)
 Location = Search(DataArray, 2)
 if Location == -1:
     print("Data not found")
 else:
     print("Data found at", Location)

Mark points

  • Calling Search() with all four sets of values 0 345 67 2
  • … outputting 'not found' or index in appropriate message each time

Part 2(f)(ii) — solution

1 mark for output showing locations for first 3 and not found for 4th 1 e.g. University Press & Assessment 2025 Page 32 of 45 9618/43 Cambridge International AS & A Level – Mark Scheme May/June 2025

Mark points

  • Include the ideas shown in the solution above.

Question 3

Paper page 7 for Q3
Original paper page 7

Part 3(a)(i) — solution

  1. Class Node header (and end)
  2. TheData declared as Integer, NextNode declared as Node
  3. Constructor header (and end) taking (min) 1 parameter …
  4. … storing parameter to TheData within constructor and storing null value to NextNode within constructor

Visual Basic (VB.NET)

Class Node
    Public TheData As Integer
    Public NextNode As Node
    Sub New(NodeData)
        TheData = NodeData
        NextNode = Nothing
    End Sub
 End Class

 University Press & Assessment 2025                       Page 33 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

class Node:
      def init (self, NodeData):
          self. TheData = NodeData #Integer
          self. NextNode = None #Node

Mark points

  • Class Node header (and end)
  • TheData declared as Integer, NextNode declared as Node
  • Constructor header (and end) taking (min) 1 parameter …
  • … storing parameter to TheData within constructor and storing null value to NextNode within constructor

Part 3(a)(ii) — solution

  1. 1 get method header (and close) taking no parameters …
  2. … returning correct value (without overwriting)
  3. 2nd correct get method

Visual Basic (VB.NET)

Function GetData()
    Return TheData
 End Function
 Function GetNextNode()
    Return NextNode
 End Function

 University Press & Assessment 2025                       Page 34 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

def GetData(self):
      return self. TheData
 def GetNextNode(self):
      return self. NextNode

Mark points

  • 1 get method header (and close) taking no parameters …
  • … returning correct value (without overwriting)
  • 2nd correct get method

Part 3(a)(iii) — solution

  1. SetNextNode() method header (and close) taking 1 parameter (of type Node) …
  2. … storing parameter in NextNode

Visual Basic (VB.NET)

Sub SetNextNode(pNextNode)
    NextNode = pNextNode
 End Sub

 University Press & Assessment 2025                       Page 35 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme            May/June 2025

Python

def SetNextNode(self, pNextNode):
      self. NextNode = pNextNode

Mark points

  • SetNextNode() method header (and close) taking 1 parameter (of type Node) …
  • … storing parameter in NextNode

Part 3(b)(i) — solution

  1. Class LinkedList header (and close) and constructor header with no parameter (and close) …
  2. … declaring HeadNode as type Node and storing null value in constructor

Visual Basic (VB.NET)

Class LinkedList
    Private HeadNode As Node
    Sub New()
        HeadNode = Nothing
    End Sub
 End Class

 University Press & Assessment 2025                       Page 36 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

class LinkedList:
      def init (self):
          self. HeadNode = None #Node

Mark points

  • Class LinkedList header (and close) and constructor header with no parameter (and close) …
  • … declaring HeadNode as type Node and storing null value in constructor

Part 3(b)(ii) — solution

  1. InsertNode()method header (and close) taking one (integer) parameter
  2. Creating new instance of Node with the parameter as the argument
  3. Calling SetNextNode() for new node with HeadNode as parameter
  4. Replacing HeadNode with new node

Visual Basic (VB.NET)

Sub InsertNode(NodeData)
    Dim TheNode As Node = New Node(NodeData)
    TheNode.SetNextNode(HeadNode)
    HeadNode = TheNode
 End Sub

 University Press & Assessment 2025                       Page 37 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

Python

def InsertNode(self, NodeData):
      TheNode = Node(NodeData)
      TheNode.SetNextNode(self. HeadNode)
      self. HeadNode = TheNode

Mark points

  • InsertNode()method header (and close) taking one (integer) parameter
  • Creating new instance of Node with the parameter as the argument
  • Calling SetNextNode() for new node with HeadNode as parameter
  • Replacing HeadNode with new node

Part 3(b)(iii) — solution

  1. Traverse() method header (and close) with no parameter and returns created string
  2. Starts at head node and follows nodes using GetNextNode() until no nodes left …
  3. … concatenates the data from each node and formats correctly

Visual Basic (VB.NET)

Function Traverse()
    Dim ReturnValue As String = ""
    Dim CurrentNode As Node = HeadNode

    While CurrentNode IsNot Nothing
       ReturnValue = ReturnValue & CurrentNode.GetData() & " "
       CurrentNode = CurrentNode.GetNextNode()
    End While
    Return ReturnValue
 End Function

 University Press & Assessment 2025                       Page 39 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme                      May/June 2025

Python

def Traverse(self):
      ReturnValue = ""
      CurrentNode = self. HeadNode
      while(CurrentNode != None):
          ReturnValue = ReturnValue + str(CurrentNode.GetData())+ " "
          CurrentNode = CurrentNode.GetNextNode()
      return ReturnValue

Mark points

  • Traverse() method header (and close) with no parameter and returns created string
  • Starts at head node and follows nodes using GetNextNode() until no nodes left …
  • … concatenates the data from each node and formats correctly

Part 3(b)(iv) — solution

  1. RemoveNode() method header (and close) taking (integer) parameter and returning Boolean in all cases
  2. Checking if head node is null and returning FALSE
  3. Checking if head node equals parameter and returning TRUE if true …
  4. … and updating HeadNode to HeadNode.GetNextNode()
  5. Following nodes comparing data from each node to parameter …
  6. ... if found updating next node and returning TRUE
  7. … if end of list returning FALSE

Visual Basic (VB.NET)

Function RemoveNode(DataToRemove)
    If HeadNode Is Nothing Then

         Return False
      ElseIf HeadNode.GetData() = DataToRemove Then
         HeadNode = HeadNode.GetNextNode()
         Return True
      End If
      Dim Found As Boolean = False
      Dim CurrentNode As Node = HeadNode
      While Not (Found) And CurrentNode IsNot Nothing

       If ((CurrentNode).GetNextNode()).GetData() = DataToRemove Then
           CurrentNode.SetNextNode(CurrentNode.GetNextNode().GetNextNode())
           Found = True
       Else
           CurrentNode = CurrentNode.GetNextNode()
       End If
    End While
    Return Found
 End Function

 University Press & Assessment 2025                       Page 42 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme                                   May/June 2025

Python

def RemoveNode(self, DataToRemove):
      if self. HeadNode == None:
          return False
      elif self. HeadNode.GetData() == DataToRemove:
          self. HeadNode = self. HeadNode.GetNextNode()
          return True
      Found = False
      CurrentNode = self. HeadNode
      while not(Found) and CurrentNode != None:
          if ((CurrentNode).GetNextNode()).GetData() == DataToRemove:
              CurrentNode.SetNextNode(CurrentNode.GetNextNode().GetNextNode())
              Found = True
          else:
              CurrentNode = CurrentNode.GetNextNode()

Mark points

  • RemoveNode() method header (and close) taking (integer) parameter and returning Boolean in all cases
  • Checking if head node is null and returning FALSE
  • Checking if head node equals parameter and returning TRUE if true …
  • … and updating HeadNode to HeadNode.GetNextNode()
  • Following nodes comparing data from each node to parameter …
  • ... if found updating next node and returning TRUE
  • … if end of list returning FALSE

Part 3(c)(i) — solution

  1. Creating new LinkedList object
  2. Calling InsertNode() five times with correct data in correct order
  3. Calling RemoveNode(30) and calling Traverse() and store/output the return value, before RemoveNode() and

Visual Basic (VB.NET)

Sub Main(args As String())
    Dim CreateList As LinkedList = New LinkedList()
    Dim ReturnValue1 As String
    Dim ReturnValue2 As String

 University Press & Assessment 2025                       Page 44 of 45

9618/43                                          Cambridge International AS & A Level – Mark Scheme   May/June 2025

    CreateList.InsertNode(10)
    CreateList.InsertNode(20)
    CreateList.InsertNode(30)
    CreateList.InsertNode(40)
    CreateList.InsertNode(50)
    ReturnValue1 = (CreateList.Traverse())
    CreateList.RemoveNode(30)
    ReturnValue2 = (CreateList.Traverse())
    Console.ReadLine()
 End Sub

Python

CreateList = LinkedList()

 CreateList.InsertNode(10)
 CreateList.InsertNode(20)
 CreateList.InsertNode(30)
 CreateList.InsertNode(40)
 CreateList.InsertNode(50)
 ReturnValue1 = (CreateList.Traverse())
 CreateList.RemoveNode(30)
 ReturnValue2 = (CreateList.Traverse())

Mark points

  • Creating new LinkedList object
  • Calling InsertNode() five times with correct data in correct order
  • Calling RemoveNode(30) and calling Traverse() and store/output the return value, before RemoveNode() and

Part 3(c)(ii) — solution

  1. Output of linked list with 50 40 30 20 10
  2. Output of 2nd linked list with 50 40 20 10

Mark points

  • Output of linked list with 50 40 30 20 10
  • Output of 2nd linked list with 50 40 20 10