9618/42 · October/November 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)(i) — solution

  1. Class header (and end)
  2. 4 private attributes with correct data types
  3. Constructor header (and end) taking 2 parameters within class …
  4. … within constructor assigning parameters to Species and DistancePerHour and assigning 500.0 to XPosition

Visual Basic (VB.NET)

Class Bird
                        Private Species As String
                        Private DistancePerHour As Single
                        Private XPosition As Single
                        Private YPosition As Single
                        Sub New(pDistancePerHour, pSpecies)
                            Species = pSpecies
                            DistancePerHour = pDistancePerHour
                            XPosition = 500.0
                            YPosition = 500.0
                        End Sub
                End Class

 University Press & Assessment 2025                       Page 6 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Class header (and end)
  • 4 private attributes with correct data types
  • Constructor header (and end) taking 2 parameters within class …
  • … within constructor assigning parameters to Species and DistancePerHour and assigning 500.0 to XPosition

Part 1(a)(i) — solution

  1. self.__Species = pSpecies #string
  2. self.__DistancePerHour = pDistancePerHour #real
  3. self.__XPosition = 500.0 #real
  4. self.__YPosition = 500.0 #real

Python

class Bird:
                     def __init__(self, pDistancePerHour, pSpecies):
                         self.__Species = pSpecies #string
                         self.__DistancePerHour = pDistancePerHour #real
                         self.__XPosition = 500.0 #real
                         self.__YPosition = 500.0 #real

Mark points

  • self.__Species = pSpecies #string
  • self.__DistancePerHour = pDistancePerHour #real
  • self.__XPosition = 500.0 #real
  • self.__YPosition = 500.0 #real

Part 1(a)(ii) — solution

  1. Get method header (and end) with no parameter …
  2. … returning Species

Visual Basic (VB.NET)

Function GetSpecies()
                    Return Species
                End Function

Python

def GetSpecies(self):
                     return self.__Species

 University Press & Assessment 2025                       Page 7 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Get method header (and end) with no parameter …
  • … returning Species

Part 1(a)(iii) — solution

  1. Get method header (and end) with no parameter, returning a value
  2. Creating correct string using attributes …
  3. … returning this string

Visual Basic (VB.NET)

Function GetPosition()
                    Dim ReturnValue As String = "X = " & XPosition & " Y = " & YPosition
                    Return ReturnValue
                End Function

Python

def GetPosition(self):
                     ReturnValue = "X = " + str(self.__XPosition) + " Y = " + str(self.__YPosition)
                     return ReturnValue

 University Press & Assessment 2025                       Page 8 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme      October/November 2025

Mark points

  • Get method header (and end) with no parameter, returning a value
  • Creating correct string using attributes …
  • … returning this string

Part 1(a)(iv) — solution

  1. Method header (and end) taking direction and minutes flying as parameters
  2. Calculation of distance using minutes flying parameter and attribute DistancePerHour
  3. Selection based on direction parameter …
  4. … north adding to YPosition and south subtracting from YPosition
  5. … east adding to XPosition and west subtracting from XPosition

Mark points

  • Method header (and end) taking direction and minutes flying as parameters
  • Calculation of distance using minutes flying parameter and attribute DistancePerHour
  • Selection based on direction parameter …
  • … north adding to YPosition and south subtracting from YPosition
  • … east adding to XPosition and west subtracting from XPosition

Part 1(a)(iv) — solution

  1. If Direction = "E" Then
  2. XPosition = XPosition + ((DistancePerHour / 60) * MinsFlying)
  3. ElseIf Direction = "W" Then
  4. XPosition = XPosition - ((DistancePerHour / 60) * MinsFlying)
  5. ElseIf Direction = "N" Then
  6. YPosition = YPosition + ((DistancePerHour / 60) * MinsFlying)
  7. ElseIf Direction = "S" Then
  8. YPosition = YPosition - ((DistancePerHour / 60) * MinsFlying)
  9. if Direction == "E":
  10. self.__XPosition = self.__XPosition + ((self.__DistancePerHour/60)*MinsFlying)
  11. elif Direction == "W":
  12. self.__XPosition = self.__XPosition - ((self.__DistancePerHour/60)*MinsFlying)
  13. elif Direction == "N":
  14. self.__YPosition = self.__YPosition + ((self.__DistancePerHour/60)*MinsFlying)
  15. elif Direction == "S":
  16. self.__YPosition = self.__YPosition - ((self.__DistancePerHour/60)*MinsFlying)

Visual Basic (VB.NET)

Function Move(Direction, MinsFlying)
                    If Direction = "E" Then
                        XPosition = XPosition + ((DistancePerHour / 60) * MinsFlying)

                      ElseIf Direction = "W" Then
                          XPosition = XPosition - ((DistancePerHour / 60) * MinsFlying)

                      ElseIf Direction = "N" Then
                          YPosition = YPosition + ((DistancePerHour / 60) * MinsFlying)

                      ElseIf Direction = "S" Then
                          YPosition = YPosition - ((DistancePerHour / 60) * MinsFlying)

                    End If
                End Function

Python

def Move(self, Direction, MinsFlying):
                     if Direction == "E":
                         self.__XPosition = self.__XPosition + ((self.__DistancePerHour/60)*MinsFlying)

                      elif Direction == "W":
                          self.__XPosition = self.__XPosition - ((self.__DistancePerHour/60)*MinsFlying)

                      elif Direction == "N":
                          self.__YPosition = self.__YPosition + ((self.__DistancePerHour/60)*MinsFlying)

                      elif Direction == "S":
                          self.__YPosition = self.__YPosition - ((self.__DistancePerHour/60)*MinsFlying)

 University Press & Assessment 2025                       Page 10 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • If Direction = "E" Then
  • XPosition = XPosition + ((DistancePerHour / 60) * MinsFlying)
  • ElseIf Direction = "W" Then
  • XPosition = XPosition - ((DistancePerHour / 60) * MinsFlying)
  • ElseIf Direction = "N" Then
  • YPosition = YPosition + ((DistancePerHour / 60) * MinsFlying)
  • ElseIf Direction = "S" Then
  • YPosition = YPosition - ((DistancePerHour / 60) * MinsFlying)
  • if Direction == "E":
  • self.__XPosition = self.__XPosition + ((self.__DistancePerHour/60)*MinsFlying)
  • elif Direction == "W":
  • self.__XPosition = self.__XPosition - ((self.__DistancePerHour/60)*MinsFlying)
  • elif Direction == "N":
  • self.__YPosition = self.__YPosition + ((self.__DistancePerHour/60)*MinsFlying)
  • elif Direction == "S":
  • self.__YPosition = self.__YPosition - ((self.__DistancePerHour/60)*MinsFlying)

Part 1(b) — solution

  1. Cockatiel 71.0 instance of Bird created …
  2. Macaw 56.0 instance of Bird created …
  3. … both stored in variables/structures

Visual Basic (VB.NET)

Dim FirstBird As Bird = New Bird(71.0, "Cockatiel")
                Dim SecondBird As Bird = New Bird(56.0, "Macaw")

Python

FirstBird = Bird(71.0, "Cockatiel")
                SecondBird = Bird(56.0, "Macaw")

 University Press & Assessment 2025                       Page 11 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Cockatiel 71.0 instance of Bird created …
  • Macaw 56.0 instance of Bird created …
  • … both stored in variables/structures

Part 1(c)(i) — solution

  1. Output species, X and Y position for both Bird objects in appropriate messages(s)
  2. Prompt and input of bird choice, time and direction …
  3. … validating all three inputs …
  4. … looping until all three are valid
  5. Calling Move() for chosen bird …
  6. … with only input direction and input time as arguments
  7. Outputting new position for the bird moved
  8. Using get methods throughout where appropriate

Mark points

  • Output species, X and Y position for both Bird objects in appropriate messages(s)
  • Prompt and input of bird choice, time and direction …
  • … validating all three inputs …
  • … looping until all three are valid
  • Calling Move() for chosen bird …
  • … with only input direction and input time as arguments
  • Outputting new position for the bird moved
  • Using get methods throughout where appropriate

Part 1(c)(i) — solution

  1. Valid = true;
  2. Direction = scanner.nextLine().toUpperCase();
  3. if(Direction.compareTo("NORTH") == 0 || Direction.compareTo("N") == 0){
  4. if(Choice == 1){
  5. } else if(Direction.compareTo("SOUTH")== 0 || Direction.compareTo("S") == 0){
  6. if(Choice == 1){
  7. } else if(Direction.compareTo("EAST")== 0 || Direction.compareTo("E") == 0){
  8. if(Choice == 1){
  9. } else if(Direction.compareTo("WEST")== 0 || Direction.compareTo("W") == 0){
  10. if(Choice == 1){
  11. Valid = false;
  12. Choice = 0
  13. Choice = Console.ReadLine
  14. Time = -1
  15. Time = Console.ReadLine
  16. Dim Valid As Boolean = False
  17. While (Valid = False)
  18. Valid = True
  19. Direction = Console.ReadLine().ToUpper
  20. If Direction = "NORTH" Or Direction = "N" Then

Visual Basic (VB.NET)

Dim Choice As Integer
                Dim Time As Integer
                Dim Direction As String

                Choice = 0

                While Choice <> 1 And Choice <> 2
                    Console.WriteLine("Which bird do you want to move")
                    Console.WriteLine("Enter 1 for " & FirstBird.GetSpecies() & " is currently at " &
                FirstBird.GetPosition())
                    Console.WriteLine("Enter 2 for " & SecondBird.GetSpecies() & " is currently at " &
                SecondBird.GetPosition())
                    Choice = Console.ReadLine
                End While
                Time = -1
                While Time < 0 Or Time > 500
                    Console.WriteLine("To the nearest minute how long has the bird been flying ")
                    Time = Console.ReadLine
                End While
                Dim Valid As Boolean = False
                While (Valid = False)
                    Valid = True

                      Console.WriteLine("Which direction has the bird been flying, North, South, East or West
                ")
                      Direction = Console.ReadLine().ToUpper
                      If Direction = "NORTH" Or Direction = "N" Then
                          If Choice = 1 Then
                              FirstBird.Move("N", Time)
                          Else
                              SecondBird.Move("N", Time)
                          End If

 University Press & Assessment 2025                       Page 14 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Valid = true;
  • Direction = scanner.nextLine().toUpperCase();
  • if(Direction.compareTo("NORTH") == 0 || Direction.compareTo("N") == 0){
  • if(Choice == 1){
  • } else if(Direction.compareTo("SOUTH")== 0 || Direction.compareTo("S") == 0){
  • if(Choice == 1){
  • } else if(Direction.compareTo("EAST")== 0 || Direction.compareTo("E") == 0){
  • if(Choice == 1){
  • } else if(Direction.compareTo("WEST")== 0 || Direction.compareTo("W") == 0){
  • if(Choice == 1){
  • Valid = false;
  • Choice = 0
  • Choice = Console.ReadLine
  • Time = -1
  • Time = Console.ReadLine
  • Dim Valid As Boolean = False
  • While (Valid = False)
  • Valid = True
  • Direction = Console.ReadLine().ToUpper
  • If Direction = "NORTH" Or Direction = "N" Then

Part 1(c)(i) — solution

  1. ElseIf Direction = "SOUTH" Or Direction = "S" Then
  2. If Choice = 1 Then
  3. ElseIf Direction = "EAST" Or Direction = "E" Then
  4. If Choice = 1 Then
  5. ElseIf Direction = "WEST" Or Direction = "W" Then
  6. If Choice = 1 Then
  7. Valid = False
  8. Choice = 0
  9. while Choice != 1 and Choice != 2:
  10. Choice = -1

Python

Choice = 0
                while Choice != 1 and Choice != 2:
                     print("Which bird do you want to move")
                     print("Enter 1 for", FirstBird.GetSpecies(), "is currently at",
                FirstBird.GetPosition())
                     Choice = -1

                    print("Enter 2 for", SecondBird.GetSpecies(), "is currently at",
                SecondBird.GetPosition())

 University Press & Assessment 2025                       Page 15 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • ElseIf Direction = "SOUTH" Or Direction = "S" Then
  • If Choice = 1 Then
  • ElseIf Direction = "EAST" Or Direction = "E" Then
  • If Choice = 1 Then
  • ElseIf Direction = "WEST" Or Direction = "W" Then
  • If Choice = 1 Then
  • Valid = False
  • Choice = 0
  • while Choice != 1 and Choice != 2:
  • Choice = -1

Part 1(c)(i) — solution

  1. Choice = int(input())
  2. Time = -1
  3. Time = int(input("To the nearest minute how long has the bird been flying "))
  4. Valid = False
  5. while Valid == False:
  6. Valid = True
  7. Direction = input("Which direction has the bird been flying, North, South, East or West
  8. if Direction == "NORTH" or Direction == "N":
  9. if Choice == 1:
  10. elif Direction == "SOUTH" or Direction == "S":
  11. if Choice == 1:
  12. elif Direction == "EAST" or Direction == "E":
  13. if Choice == 1:
  14. elif Direction == "WEST" or Direction == "W":
  15. if Choice == 1:
  16. Valid = False

Mark points

  • Choice = int(input())
  • Time = -1
  • Time = int(input("To the nearest minute how long has the bird been flying "))
  • Valid = False
  • while Valid == False:
  • Valid = True
  • Direction = input("Which direction has the bird been flying, North, South, East or West
  • if Direction == "NORTH" or Direction == "N":
  • if Choice == 1:
  • elif Direction == "SOUTH" or Direction == "S":
  • if Choice == 1:
  • elif Direction == "EAST" or Direction == "E":
  • if Choice == 1:
  • elif Direction == "WEST" or Direction == "W":
  • if Choice == 1:
  • Valid = False

Part 1(c)(ii) — solution

  1. screenshot showing inputs for one test with correct output
  2. screenshot showing inputs for a second test with correct output
  3. screenshot showing inputs for a third and fourth test with correct output

Mark points

  • screenshot showing inputs for one test with correct output
  • screenshot showing inputs for a second test with correct output
  • screenshot showing inputs for a third and fourth test with correct output

Question 2

Paper page 6 for Q2
Original paper page 6

Part 2(a) — solution

  1. Creation of 1D array …
  2. … with 20 generated random integers between 0 and 100 (inclusive) …
  3. … all 20 random integers are unique

Visual Basic (VB.NET)

Dim RandomNumber As Random = New Random()
                Dim TheArray(19) As Integer
                Dim Generated As Integer
                Dim X As Integer = 0

                While X < 20
                     Generated = RandomNumber.Next(0, 100)
                     If Array.IndexOf(TheArray, Generated) < 0 Then
                          TheArray(X) = Generated
                          X = X + 1
                     End If
                End While

 University Press & Assessment 2025                       Page 18 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Creation of 1D array …
  • … with 20 generated random integers between 0 and 100 (inclusive) …
  • … all 20 random integers are unique

Part 2(a) — solution

  1. TheArray = []
  2. TheArray = random.sample(range(0,101),20)

Python

TheArray = []
                TheArray = random.sample(range(0,101),20)

Mark points

  • TheArray = []
  • TheArray = random.sample(range(0,101),20)

Part 2(b) — solution

  1. Procedure header (and close) taking (array) as parameter
  2. Outputting array contents once …
  3. … on one line with a space between each integer

Visual Basic (VB.NET)

Sub PrintArray(DataArray() As Integer)
                    Dim Output As String = ""
                    For X = 0 To 19
                        Output = Output + Str(DataArray(X)) + " "
                    Next X
                    Console.WriteLine(Output)
                End Sub

Python

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

 University Press & Assessment 2025                       Page 19 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme               October/November 2025

Mark points

  • Procedure header (and close) taking (array) as parameter
  • Outputting array contents once …
  • … on one line with a space between each integer

Part 2(c) — solution

  1. Function header (and end) taking (array) parameter and returning a sorted array after sorting
  2. Outer loop …
  3. … inner loop
  4. … comparing elements and swapping into ascending order
  5. Sort must work for array of any length i.e. loops for length of parameter array

Mark points

  • Function header (and end) taking (array) parameter and returning a sorted array after sorting
  • Outer loop …
  • … inner loop
  • … comparing elements and swapping into ascending order
  • Sort must work for array of any length i.e. loops for length of parameter array

Part 2(c) — solution

  1. Dim Swap As Boolean = True
  2. While Swap = True
  3. Swap = False
  4. For X = 0 To DataArray.Length - 2
  5. Temp = DataArray(X)
  6. DataArray(X) = DataArray(X + 1)
  7. DataArray(X + 1) = Temp
  8. Swap = True
  9. Swap = True
  10. while Swap == True:
  11. Swap = False
  12. DataArray[y], DataArray[y+1] = DataArray[y+1], DataArray[y]
  13. Swap = True

Visual Basic (VB.NET)

Function BubbleSort(DataArray() As Integer)
                        Dim Swap As Boolean = True
                        Dim Temp As Integer
                        While Swap = True
                            Swap = False
                            For X = 0 To DataArray.Length - 2
                                If DataArray(X) > DataArray(X + 1) Then
                                    Temp = DataArray(X)
                                    DataArray(X) = DataArray(X + 1)
                                    DataArray(X + 1) = Temp

                                         Swap = True
                                     End If
                                 Next X
                             End While

                        Return DataArray
                End Function

Python

def BubbleSort(DataArray):
                     Swap = True

                      while Swap == True:
                          Swap = False
                          for y in range(0, len(DataArray)-1):
                              if DataArray[y] > DataArray[y+1]:
                                  DataArray[y], DataArray[y+1] = DataArray[y+1], DataArray[y]
                                  Swap = True
                      return DataArray

 University Press & Assessment 2025                       Page 21 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme        October/November 2025

Mark points

  • Dim Swap As Boolean = True
  • While Swap = True
  • Swap = False
  • For X = 0 To DataArray.Length - 2
  • Temp = DataArray(X)
  • DataArray(X) = DataArray(X + 1)
  • DataArray(X + 1) = Temp
  • Swap = True
  • Swap = True
  • while Swap == True:
  • Swap = False
  • DataArray[y], DataArray[y+1] = DataArray[y+1], DataArray[y]
  • Swap = True

Part 2(d)(i) — solution

  1. Calling PrintArray() with array as argument
  2. Calling BubbleSort() with array as argument and storing/using return value
  3. Outputting "Sorted" and calling PrintArray() with (returned) array as argument

Visual Basic (VB.NET)

PrintArray(TheArray)
                Dim SortedArray(19) As Integer
                SortedArray = BubbleSort(TheArray)
                Console.WriteLine("Sorted")
                PrintArray(SortedArray)

Python

PrintArray(TheArray)
                SortedArray = BubbleSort(TheArray)
                print("Sorted")
                PrintArray(SortedArray)

Mark points

  • Calling PrintArray() with array as argument
  • Calling BubbleSort() with array as argument and storing/using return value
  • Outputting "Sorted" and calling PrintArray() with (returned) array as argument

Part 2(d)(ii) — solution

  1. Output shows unsorted array of 20 integers between 0 and 100 inclusive before sorting,

Mark points

  • Output shows unsorted array of 20 integers between 0 and 100 inclusive before sorting,

Part 2(e) — solution

  1. Function header (and end) taking four parameters and recursive function written
  2. Calculating middle value
  3. Comparing middle value to data parameter and returning index if equal
  4. If middle is greater than, recursive call with middle –1 for upper
  5. If middle is less than, recursive call with middle + 1 for lower
  6. Checking if not found and returning –1

Mark points

  • Function header (and end) taking four parameters and recursive function written
  • Calculating middle value
  • Comparing middle value to data parameter and returning index if equal
  • If middle is greater than, recursive call with middle –1 for upper
  • If middle is less than, recursive call with middle + 1 for lower
  • Checking if not found and returning –1

Part 2(e) — solution

  1. If Upper >= Lower Then
  2. Middle = Lower + (Upper - Lower) \ 2
  3. If DataArray(Middle) = DataToFind Then
  4. if Upper >= Lower:
  5. Middle = Lower + (Upper - Lower) // 2
  6. if DataArray[Middle] == DataToFind:

Visual Basic (VB.NET)

Function RecursiveBinarySearch(DataArray() As Integer, Lower As Integer, Upper As Integer,
                DataToFind As Integer)
                    Dim Middle As Integer
                    If Upper >= Lower Then
                        Middle = Lower + (Upper - Lower) \ 2
                        If DataArray(Middle) = DataToFind Then
                            Return Middle
                        ElseIf DataArray(Middle) > DataToFind Then
                            Return RecursiveBinarySearch(DataArray, Lower, Middle - 1, DataToFind)
                        Else
                            Return RecursiveBinarySearch(DataArray, Middle + 1, Upper, DataToFind)
                        End If
                    Else
                        Return -1
                    End If
                End Function

Python

def RecursiveBinarySearch(DataArray, Lower, Upper, DataToFind):
                     if Upper >= Lower:
                         Middle = Lower + (Upper - Lower) // 2
                         if DataArray[Middle] == DataToFind:
                             return Middle
                         elif DataArray[Middle] > DataToFind:
                             return RecursiveBinarySearch(DataArray, Lower, Middle - 1, DataToFind)
                         else:
                             return RecursiveBinarySearch(DataArray, Middle + 1, Upper, DataToFind)
                     else:
                         return -1

 University Press & Assessment 2025                       Page 24 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme            October/November 2025

Mark points

  • If Upper >= Lower Then
  • Middle = Lower + (Upper - Lower) \ 2
  • If DataArray(Middle) = DataToFind Then
  • if Upper >= Lower:
  • Middle = Lower + (Upper - Lower) // 2
  • if DataArray[Middle] == DataToFind:

Part 2(f)(i) — solution

  1. Prompt and input of integer
  2. Call of RecursiveBinarySearch(SortedArray, 0, 19, input) and storing/using return value
  3. Output of "Not found" if –1 returned and output "Found at position" with index returned if found

Visual Basic (VB.NET)

Console.WriteLine("Enter the number to find ")
                Dim DataToFind As Integer = Console.ReadLine()
                Dim Location As Integer = RecursiveBinarySearch(SortedArray, 0, 19, DataToFind)
                If Location = -1 Then
                    Console.WriteLine("Not found")
                Else
                    Console.WriteLine("Found at position " & Location)
                End If

Python

DataToFind = int(input("Enter the number to find "))
                Location = RecursiveBinarySearch(SortedArray, 0, 19, DataToFind)
                if Location == -1:
                     print("Not found")
                else:
                     print("Found at position", Location)

 University Press & Assessment 2025                       Page 25 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme                October/November 2025

Mark points

  • Prompt and input of integer
  • Call of RecursiveBinarySearch(SortedArray, 0, 19, input) and storing/using return value
  • Output of "Not found" if –1 returned and output "Found at position" with index returned if found

Part 2(f)(ii) — solution

  1. screenshot showing smallest number in array input and found message with index 0 and screenshot showing highest
  2. screenshot showing a number not in the array input and an output of "Not found"

Mark points

  • screenshot showing smallest number in array input and found message with index 0 and screenshot showing highest
  • screenshot showing a number not in the array input and an output of "Not found"

Question 3

Paper page 10 for Q3
Original paper page 10

Part 3(a) — solution

  1. (global) TreeArray declared as a 2D array with 50  3 elements …
  2. … all initialised to –1
  3. (global) RootPointer initialised to –1 and FreeNode initialised to 0

Visual Basic (VB.NET)

Dim FreeNode As Integer
                Dim TreeArray(0 To 49, 0 To 2) As Integer
                Dim RootPointer As Integer
                Sub Main(args As String())
                    For X = 0 To 49
                        TreeArray(X, 0) = -1
                        TreeArray(X, 1) = -1
                        TreeArray(X, 2) = -1
                    Next
                    RootPointer = -1
                    FreeNode = 0
                End Sub

 University Press & Assessment 2025                       Page 27 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • (global) TreeArray declared as a 2D array with 50  3 elements …
  • … all initialised to –1
  • (global) RootPointer initialised to –1 and FreeNode initialised to 0

Part 3(a) — solution

  1. TreeArray = []
  2. RootPointer = -1
  3. FreeNode = 0

Python

TreeArray = []
                for x in range(50):
                     TreeArray.append([-1,-1,-1])
                RootPointer = -1
                FreeNode = 0

 University Press & Assessment 2025                       Page 28 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme            October/November 2025

Mark points

  • TreeArray = []
  • RootPointer = -1
  • FreeNode = 0

Part 3(b) — solution

  1. Procedure header (and end) taking one (integer) parameter and storing parameter in array in index
  2. Checking if tree is full (FreeNode = 50) and outputting "The tree is full"
  3. Checking if tree is empty (RootPointer = -1 // FreeNode = 0) and if so, storing 0 in RootPointer
  4. (if not empty) Comparing parameter to data at index TreeArray[RootPointer][1] …
  5. … if less than, accessing left node …
  6. … if greater than, accessing right node …
  7. … until location found …
  8. … updating parent node's appropriate pointer
  9. Incrementing FreeNode

Mark points

  • Procedure header (and end) taking one (integer) parameter and storing parameter in array in index
  • Checking if tree is full (FreeNode = 50) and outputting "The tree is full"
  • Checking if tree is empty (RootPointer = -1 // FreeNode = 0) and if so, storing 0 in RootPointer
  • (if not empty) Comparing parameter to data at index TreeArray[RootPointer][1] …
  • … if less than, accessing left node …
  • … if greater than, accessing right node …
  • … until location found …
  • … updating parent node's appropriate pointer
  • Incrementing FreeNode

Part 3(b) — solution

  1. CurrentNode = TreeArray[CurrentNode][0];
  2. if(TreeArray[CurrentNode][2] == -1){
  3. TreeArray[CurrentNode][2] = FreeNode;
  4. Placed = true;
  5. CurrentNode = TreeArray[CurrentNode][2];
  6. If FreeNode <= 49 Then
  7. TreeArray(FreeNode, 0) = -1
  8. TreeArray(FreeNode, 1) = NodeData
  9. TreeArray(FreeNode, 2) = -1
  10. If RootPointer = -1 Then
  11. RootPointer = 0
  12. Placed = False
  13. CurrentNode = RootPointer
  14. While Placed = False
  15. If TreeArray(CurrentNode, 0) = -1 Then
  16. TreeArray(CurrentNode, 0) = FreeNode

Visual Basic (VB.NET)

Sub AddNode(NodeData)
                    Dim Placed As Boolean
                    Dim CurrentNode As Integer
                    If FreeNode <= 49 Then
                        TreeArray(FreeNode, 0) = -1
                        TreeArray(FreeNode, 1) = NodeData
                        TreeArray(FreeNode, 2) = -1

                             If RootPointer = -1 Then
                                 RootPointer = 0
                             Else
                                 Placed = False
                                 CurrentNode = RootPointer
                             While Placed = False
                                 If NodeData < TreeArray(CurrentNode, 1) Then
                                         If TreeArray(CurrentNode, 0) = -1 Then
                                             TreeArray(CurrentNode, 0) = FreeNode

 University Press & Assessment 2025                         Page 30 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • CurrentNode = TreeArray[CurrentNode][0];
  • if(TreeArray[CurrentNode][2] == -1){
  • TreeArray[CurrentNode][2] = FreeNode;
  • Placed = true;
  • CurrentNode = TreeArray[CurrentNode][2];
  • If FreeNode <= 49 Then
  • TreeArray(FreeNode, 0) = -1
  • TreeArray(FreeNode, 1) = NodeData
  • TreeArray(FreeNode, 2) = -1
  • If RootPointer = -1 Then
  • RootPointer = 0
  • Placed = False
  • CurrentNode = RootPointer
  • While Placed = False
  • If TreeArray(CurrentNode, 0) = -1 Then
  • TreeArray(CurrentNode, 0) = FreeNode

Part 3(b) — solution

  1. Placed = True
  2. CurrentNode = TreeArray(CurrentNode, 0)
  3. If TreeArray(CurrentNode, 2) = -1 Then
  4. TreeArray(CurrentNode, 2) = FreeNode
  5. Placed = True
  6. CurrentNode = TreeArray(CurrentNode, 2)
  7. FreeNode = FreeNode + 1
  8. if FreeNode <= 49:
  9. TreeArray[FreeNode][0] = -1
  10. TreeArray[FreeNode][1] = NodeData
  11. TreeArray[FreeNode][2] = -1
  12. if RootPointer == -1:
  13. RootPointer = 0
  14. Placed = False
  15. CurrentNode = RootPointer
  16. while Placed == False:

Python

def AddNode(NodeData):
                     global FreeNode
                     global TreeArray
                     global RootPointer
                     if FreeNode <= 49:
                         TreeArray[FreeNode][0] = -1
                         TreeArray[FreeNode][1] = NodeData
                         TreeArray[FreeNode][2] = -1
                         if RootPointer == -1:
                             RootPointer = 0
                         else:
                             Placed = False
                             CurrentNode = RootPointer
                             while Placed == False:
                                 if NodeData < TreeArray[CurrentNode][1]:

 University Press & Assessment 2025                       Page 31 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Placed = True
  • CurrentNode = TreeArray(CurrentNode, 0)
  • If TreeArray(CurrentNode, 2) = -1 Then
  • TreeArray(CurrentNode, 2) = FreeNode
  • Placed = True
  • CurrentNode = TreeArray(CurrentNode, 2)
  • FreeNode = FreeNode + 1
  • if FreeNode <= 49:
  • TreeArray[FreeNode][0] = -1
  • TreeArray[FreeNode][1] = NodeData
  • TreeArray[FreeNode][2] = -1
  • if RootPointer == -1:
  • RootPointer = 0
  • Placed = False
  • CurrentNode = RootPointer
  • while Placed == False:

Part 3(b) — solution

  1. if TreeArray[CurrentNode][0] == -1:
  2. TreeArray[CurrentNode][0] = FreeNode
  3. Placed = True
  4. CurrentNode = TreeArray[CurrentNode][0]
  5. if TreeArray[CurrentNode][2] == -1:
  6. TreeArray[CurrentNode][2] = FreeNode
  7. Placed = True
  8. CurrentNode = TreeArray[CurrentNode][2]
  9. FreeNode = FreeNode + 1

Mark points

  • if TreeArray[CurrentNode][0] == -1:
  • TreeArray[CurrentNode][0] = FreeNode
  • Placed = True
  • CurrentNode = TreeArray[CurrentNode][0]
  • if TreeArray[CurrentNode][2] == -1:
  • TreeArray[CurrentNode][2] = FreeNode
  • Placed = True
  • CurrentNode = TreeArray[CurrentNode][2]
  • FreeNode = FreeNode + 1

Part 3(c) — solution

  1. Opening the file to read and closing the file in an appropriate place
  2. Looping 50 times/through file/through each line/until EOF …
  3. … reading in each line …
  4. … calling AddNode() with each value read in
  5. Exception handling try, catch, except with appropriate message

Mark points

  • Opening the file to read and closing the file in an appropriate place
  • Looping 50 times/through file/through each line/until EOF …
  • … reading in each line …
  • … calling AddNode() with each value read in
  • Exception handling try, catch, except with appropriate message

Part 3(c) — solution

  1. File= open("TreeData.txt")

Visual Basic (VB.NET)

Try
                    Dim FileReader As New System.IO.StreamReader("TreeData.txt")
                    While Not FileReader.EndOfStream
                        AddNode(FileReader.ReadLine())
                    End While
                    FileReader.Close()
                Catch ex As Exception
                    Console.WriteLine("Cannot open file")
                End Try

Python

try:
                     File= open("TreeData.txt")
                     for Line in File:
                         AddNode(int(Line.strip()))
                     File.close()
                except:
                     print("Error cannot open file")

 University Press & Assessment 2025                       Page 34 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme                       October/November 2025

Mark points

  • File= open("TreeData.txt")

Part 3(d) — solution

  1. Procedure header (and end) and with exception handling for writing to file: try, catch, except with appropriate message
  2. Opening the file (Tree.txt) to write and closing the file in appropriate place
  3. Looping through each element in array …
  4. … creating correct string
  5. … writing each string to the file

Mark points

  • Procedure header (and end) and with exception handling for writing to file: try, catch, except with appropriate message
  • Opening the file (Tree.txt) to write and closing the file in appropriate place
  • Looping through each element in array …
  • … creating correct string
  • … writing each string to the file

Part 3(d) — solution

  1. Dim FileWriter As IO.StreamWriter = New IO.StreamWriter("Tree.txt", False)
  2. For x = 0 To 49
  3. Line = TreeArray(x, 0) & "," & TreeArray(x, 1) & "," & TreeArray(x, 2)
  4. File = open("Tree.txt","a+")
  5. Line = str(TreeArray[x][0]) + "," + str(TreeArray[x][1])+ "," +

Visual Basic (VB.NET)

Sub WriteAllToFile()
                    Dim FileWriter As IO.StreamWriter = New IO.StreamWriter("Tree.txt", False)
                    Dim Line As String
                    Try
                        For x = 0 To 49
                            Line = TreeArray(x, 0) & "," & TreeArray(x, 1) & "," & TreeArray(x, 2)
                            FileWriter.WriteLine(Line)
                        Next
                        FileWriter.Close()
                    Catch ex As Exception
                        Console.WriteLine("Cannot open or write to file")
                    End Try
                End Sub

Python

def WriteAllToFile():
                     try:
                         File = open("Tree.txt","a+")
                         for x in range(0, 50):
                             Line = str(TreeArray[x][0]) + "," + str(TreeArray[x][1])+ "," +
                str(TreeArray[x][2]) + "\n"
                             File.write(Line)
                         File.close()
                     except:
                         print("Cannot write to file")

 University Press & Assessment 2025                       Page 36 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme   October/November 2025

Mark points

  • Dim FileWriter As IO.StreamWriter = New IO.StreamWriter("Tree.txt", False)
  • For x = 0 To 49
  • Line = TreeArray(x, 0) & "," & TreeArray(x, 1) & "," & TreeArray(x, 2)
  • File = open("Tree.txt","a+")
  • Line = str(TreeArray[x][0]) + "," + str(TreeArray[x][1])+ "," +

Part 3(e)(i) — solution

1 mark for calling WriteAllToFile() 1 Example program code VB.NET WriteAllToFile() Python WriteAllToFile() University Press & Assessment 2025 Page 37 of 38 9618/42 Cambridge International AS & A Level – Mark Scheme October/November 2025

Visual Basic (VB.NET)

WriteAllToFile()

Python

WriteAllToFile()

 University Press & Assessment 2025                       Page 37 of 38

9618/42                                          Cambridge International AS & A Level – Mark Scheme                    October/November 2025

Mark points

  • Include the ideas shown in the solution above.

Part 3(e)(ii) — solution

1 mark for a screenshot that shows correct data stored, each node on a new line (in correct format). 1 The screenshot must include the filename. e.g. University Press & Assessment 2025 Page 38 of 38

Mark points

  • Include the ideas shown in the solution above.