9618/43 · October/November 2024 · 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. Function declaration (and close where appropriate)
  2. Declaration/use of an array (with space/initialised with 45 spaces/strings)
  3. Opening the file Data.txt for read and closing in an appropriate place
  4. Looping through all file contents/Looping 45 times and reading each line …
  5. … storing all items from file into array
  6. Returning the populated array
  7. Exception handling with suitable try, catch and output

Visual Basic (VB.NET)

Function ReadData()
                        Dim TextFile As String = "Data.txt"

                              Dim Colours(45) As String
                              Try
                                  Dim FileReader As New System.IO.StreamReader(TextFile)
                                  For x = 0 To 45
                                      Colours(x) = FileReader.ReadLine()

 University Press & Assessment 2024                        Page 4 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

def ReadData():
                     Colours = []
                     try:
                          File = open("Data.txt")
                          Colours = File.read().split("\n")
                          File.close()
                          return Colours
                     except:
                          print("No file found")

Mark points

  • Function declaration (and close where appropriate)
  • Declaration/use of an array (with space/initialised with 45 spaces/strings)
  • Opening the file Data.txt for read and closing in an appropriate place
  • Looping through all file contents/Looping 45 times and reading each line …
  • … storing all items from file into array
  • Returning the populated array
  • Exception handling with suitable try, catch and output

Part 1(a) — solution

Next FileReader.Close() Catch ex As Exception Console.WriteLine("No file found") End Try Return Colours End Function

Mark points

  • Include the ideas shown in the solution above.

Part 1(b)(i) — solution

  1. Function header (and end where appropriate) taking (min) one parameter
  2. Looping through each parameter array element, concatenating with space and returning

Visual Basic (VB.NET)

Function FormatArray(DataArray)
                    Dim OutputText As String = ""
                    For X = 0 To 44
                         OutputText = OutputText & DataArray(X) & " "
                    Next
                    Return OutputText
                End Function

Python

def FormatArray(DataArray):
                     OutputText = ""
                     for x in range(0, 45):
                         OutputText = OutputText + DataArray[x] + " "
                     return OutputText

Mark points

  • Function header (and end where appropriate) taking (min) one parameter
  • Looping through each parameter array element, concatenating with space and returning

Part 1(b)(ii) — solution

  1. Calling ReadData() and storing returned array …
  2. … calling FormatArray() with returned array
  3. Outputting return value from FormatArray()

Visual Basic (VB.NET)

Dim Colours(45) As String
                Colours = ReadData()
                Console.WriteLine(FormatArray(Colours))

Python

Colours = ReadData() #string array
                print(FormatArray(Colours))

Mark points

  • Calling ReadData() and storing returned array …
  • … calling FormatArray() with returned array
  • Outputting return value from FormatArray()

Part 1(b)(iii) — solution

1 mark for output showing all colours in one string 1 e.g. University Press & Assessment 2024 Page 7 of 37 9618/43 Cambridge International AS & A Level – Mark Scheme October/November 2024

Mark points

  • Include the ideas shown in the solution above.

Part 1(c) — solution

  1. Function header (and close where appropriate) taking (min) two parameters and returns a value in all cases
  2. Looping through each character in each string parameter …
  3. … return 1 when first parameter  second
  4. … return 2 when first parameter  second

Visual Basic (VB.NET)

Function CompareStrings(FirstS, SecondS)
                    Dim Count As Integer = 1
                    While (True)
                        If Mid(FirstS, Count, 1) < Mid(SecondS, Count, 1) Then
                             Return 1
                        ElseIf Mid(FirstS, Count, 1) > Mid(SecondS, Count, 1) Then
                             Return 2
                        Else
                             Count = Count + 1
                        End If
                    End While
                End Function

 University Press & Assessment 2024                       Page 8 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme          October/November 2024

Python

def CompareStrings(First, Second):
                     Count = 0
                     while True:
                         if First[Count] < Second[Count]:
                             return 1
                         elif First[Count] > Second[Count]:
                             return 2
                         else:
                             Count = Count + 1

Mark points

  • Function header (and close where appropriate) taking (min) two parameters and returns a value in all cases
  • Looping through each character in each string parameter …
  • … return 1 when first parameter  second
  • … return 2 when first parameter  second

Part 1(c) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 1(d)(i) — solution

  1. Bubble sort function header taking array parameter and returns sorted array in all cases
  2. Comparing strings using CompareStrings() and correctly swapping values when needed
  3. Correct bubble sort that sorts the data correctly

Python

def Bubble(DataArray):
                     ArrayLength = len(DataArray)

                       for x in range(ArrayLength - 1):
                           for y in range(0, ArrayLength - x - 1):
                               Result = CompareStrings(DataArray[y], DataArray[y + 1])
                               if Result == 2:
                                   DataArray[y], DataArray[y+1] = DataArray[y+1], DataArray[y]
                       return DataArray

 University Press & Assessment 2024                       Page 9 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Bubble sort function header taking array parameter and returns sorted array in all cases
  • Comparing strings using CompareStrings() and correctly swapping values when needed
  • Correct bubble sort that sorts the data correctly

Part 1(d)(i) — solution

  1. Dim ArrayLength As Integer = 45
  2. For X = 0 To ArrayLength - 1
  3. For Y = 0 To ArrayLength - X - 2
  4. Result = CompareStrings(DataArray(Y), DataArray(Y + 1))
  5. If Result = 2 Then
  6. Temp = DataArray(Y)
  7. DataArray(Y) = DataArray(Y + 1)
  8. DataArray(Y + 1) = Temp

Visual Basic (VB.NET)

Function Bubble(DataArray)
                        Dim ArrayLength As Integer = 45
                        Dim Result As Integer
                        Dim Temp As String

                              For X = 0 To ArrayLength - 1
                                   For Y = 0 To ArrayLength - X - 2
                                        Result = CompareStrings(DataArray(Y), DataArray(Y + 1))
                                        If Result = 2 Then
                                            Temp = DataArray(Y)
                                            DataArray(Y) = DataArray(Y + 1)
                                            DataArray(Y + 1) = Temp
                                        End If
                                   Next
                              Next
                              Return DataArray

                End Function

Mark points

  • Dim ArrayLength As Integer = 45
  • For X = 0 To ArrayLength - 1
  • For Y = 0 To ArrayLength - X - 2
  • Result = CompareStrings(DataArray(Y), DataArray(Y + 1))
  • If Result = 2 Then
  • Temp = DataArray(Y)
  • DataArray(Y) = DataArray(Y + 1)
  • DataArray(Y + 1) = Temp

Part 1(d)(i) — solution

  1. if (Result == 2){
  2. Temp = DataArray[Y];
  3. DataArray[Y] = DataArray[Y+1];
  4. DataArray[Y+1] = Temp;

Mark points

  • if (Result == 2){
  • Temp = DataArray[Y];
  • DataArray[Y] = DataArray[Y+1];
  • DataArray[Y+1] = Temp;

Part 1(d)(ii) — solution

  1. Calling Bubble() with array as parameter and using/storing return value
  2. Calling FormatArray() with return value from Bubble() and outputting return value

Visual Basic (VB.NET)

Dim BubbleSorted(45) As String
                BubbleSorted = Bubble(Colours)
                Console.WriteLine(FormatArray(BubbleSorted))

Python

BubbleSorted = Bubble(Colours)
                print(FormatArray(BubbleSorted))

Mark points

  • Calling Bubble() with array as parameter and using/storing return value
  • Calling FormatArray() with return value from Bubble() and outputting return value

Part 1(d)(iii) — solution

1 mark for sorted data 1 e.g. University Press & Assessment 2024 Page 11 of 37 9618/43 Cambridge International AS & A Level – Mark Scheme October/November 2024

Mark points

  • Include the ideas shown in the solution above.

Question 2

Paper page 6 for Q2
Original paper page 6

Part 2(a)(i) — solution

  1. Class Horse declaration (and end where appropriate)
  2. All 3 attributes declared as private with appropriate data types (declaration or comment)
  3. Constructor header (and end) taking 3 parameters (constructor must be within class) …
  4. … constructor assigns parameters to attributes

Visual Basic (VB.NET)

Class Horse
                        Private Name As String
                        Private MaxFenceHeight As Integer
                        Private PercentageSuccess As Integer
                   Sub New(PName, PMaxFenceHeight, PPercentageSuccess)
                            Name = PName
                            MaxFenceHeight = PMaxFenceHeight
                            PercentageSuccess = PPercentageSuccess
                        End Sub
                End Class

 University Press & Assessment 2024                        Page 12 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

class Horse:
                     def __init__(self, PName, PMaxFenceHeight, PPercentageSuccess):
                         self.__Name = PName #String
                         self.__MaxFenceHeight = PMaxFenceHeight #Integer
                         self.__PercentageSuccess = PPercentageSuccess #Integer

Mark points

  • Class Horse declaration (and end where appropriate)
  • All 3 attributes declared as private with appropriate data types (declaration or comment)
  • Constructor header (and end) taking 3 parameters (constructor must be within class) …
  • … constructor assigns parameters to attributes

Part 2(a)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(a)(ii) — solution

  1. 1 get method header with no parameter …
  2. … returning correct attribute (without change)
  3. 2nd get method correct

Visual Basic (VB.NET)

Function GetName()
                    Return Name
                End Function

 University Press & Assessment 2024                       Page 13 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme                      October/November 2024

Python

def GetName(self):
                     return self.__Name
                def GetMaxFenceHeight(self):
                     return self.__MaxFenceHeight

Mark points

  • 1 get method header with no parameter …
  • … returning correct attribute (without change)
  • 2nd get method correct

Part 2(a)(ii) — solution

Function GetMaxFenceHeight() Return MaxFenceHeight End Function

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(i) — solution

  1. Instantiating one object of type Horse with correct data …
  2. … and storing in first element of a 1D array Horses
  3. Instantiating second object of type Horse with correct data and storing in second index of the array
  4. Outputting name of both horse objects from array …
  5. … using GetName()

Visual Basic (VB.NET)

Dim Horses(2) As Horse
                Horses(0) = New Horse("Beauty", 150, 72)
                Horses(1) = New Horse("Jet", 160, 65)
                Console.WriteLine(Horses(0).GetName())
                Console.WriteLine(Horses(1).GetName())

 University Press & Assessment 2024                        Page 14 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme              October/November 2024

Python

Horses = []
                Horses.append(Horse("Beauty", 150, 72))
                Horses.append(Horse("Jet", 160, 65))
                print(Horses[0].GetName())
                print(Horses[1].GetName())

Mark points

  • Instantiating one object of type Horse with correct data …
  • … and storing in first element of a 1D array Horses
  • Instantiating second object of type Horse with correct data and storing in second index of the array
  • Outputting name of both horse objects from array …
  • … using GetName()

Part 2(b)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(b)(ii) — solution

1 mark for both names output: 1

Mark points

  • Include the ideas shown in the solution above.

Part 2(c)(i) — solution

  1. Class Fence header (and end where appropriate) with no inheritance
  2. Height and Risk private with integer data type
  3. Constructor taking 2 parameters and storing in attributes (constructor must be within class)
  4. 2 get methods (no parameter) returning correct attributes (within class)

Python

class Fence:
                     def __init__(self, PHeight, PRisk):
                         self.__Height = PHeight #integer
                         self.__Risk = PRisk #integer

                       def GetHeight(self):
                           return self.__Height
                       def GetRisk(self):
                           return self.__Risk

 University Press & Assessment 2024                        Page 15 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Class Fence header (and end where appropriate) with no inheritance
  • Height and Risk private with integer data type
  • Constructor taking 2 parameters and storing in attributes (constructor must be within class)
  • 2 get methods (no parameter) returning correct attributes (within class)

Part 2(c)(i) — solution

  1. Height = PHeight
  2. Risk = PRisk

Visual Basic (VB.NET)

Class Fence
                        Dim Height As Integer
                        Dim Risk As Integer

                              Sub New(PHeight, PRisk)
                                  Height = PHeight
                                  Risk = PRisk
                              End Sub
                              Function GetHeight()
                                  Return Height
                              End Function

                        Function GetRisk()
                            Return Risk
                        End Function
                End Class

Mark points

  • Height = PHeight
  • Risk = PRisk

Part 2(c)(i) — solution

public Integer GetHeight(){ return Height; } public Integer GetRisk(){ return Risk; } }

Mark points

  • Include the ideas shown in the solution above.

Part 2(c)(ii) — solution

  1. Declaration/use of array Course of type Fence (with at least 4 elements)
  2. Taking Height and Risk as input four times and store/use
  3. Instantiating a Fence object for each set of valid input values and storing in array
  4. Taking each height as input until it is between 70 and 180 (inclusive)
  5. Taking each risk as input until it is between 1 and 5 (inclusive)

Python

Course = []
                for x in range(0, 4):
                     Valid = False
                     while Valid == False:
                         Height = int(input("Enter the height in cm"))
                         if(Height >= 70 and Height <= 180):
                             Valid = True
                     Valid = False
                     while Valid == False:
                         Risk = int(input("Enter the risk between 1 (easy) and 5 (hard)"))
                         if(Risk >= 1 and Risk <= 5):
                             Valid = True
                     Course.append(Fence(Height, Risk))

 University Press & Assessment 2024                         Page 17 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Declaration/use of array Course of type Fence (with at least 4 elements)
  • Taking Height and Risk as input four times and store/use
  • Instantiating a Fence object for each set of valid input values and storing in array
  • Taking each height as input until it is between 70 and 180 (inclusive)
  • Taking each risk as input until it is between 1 and 5 (inclusive)

Part 2(c)(ii) — solution

  1. For x = 0 To 3
  2. Height = Console.ReadLine()
  3. Loop Until Height >= 70 And Height <= 180
  4. Risk = Console.ReadLine()
  5. Loop Until Risk >= 1 And Risk <= 5
  6. Course(x) = New Fence(Height, Risk)

Visual Basic (VB.NET)

Dim Course(5) As Fence
                Dim Height As Integer
                Dim Risk As Integer
                For x = 0 To 3
                   Do
                        Console.WriteLine("Enter the height in cm")
                        Height = Console.ReadLine()
                   Loop Until Height >= 70 And Height <= 180
                   Do
                        Console.WriteLine("Enter the risk between 1 (easy) and 5 (hard)")
                        Risk = Console.ReadLine()
                   Loop Until Risk >= 1 And Risk <= 5
                   Course(x) = New Fence(Height, Risk)
                Next

Mark points

  • For x = 0 To 3
  • Height = Console.ReadLine()
  • Loop Until Height >= 70 And Height <= 180
  • Risk = Console.ReadLine()
  • Loop Until Risk >= 1 And Risk <= 5
  • Course(x) = New Fence(Height, Risk)

Part 2(d) — solution

  1. Method header taking 2 parameters (and end where appropriate, returning real)
  2. Checking if fence height parameter is more than max attribute for that horse, if true multiplying percentage success by
  3. (Otherwise) selection checking risk value parameter between 1 and 5, multiplying modifier by percentage success
  4. Returning correct value as a real number in all instances
  5. Correct use of attributes and parameters throughout

Visual Basic (VB.NET)

Function Success(Height, Risk)
                        If Height > MaxFenceHeight Then
                             Return PercentageSuccess * 0.2
                        Else

 University Press & Assessment 2024                        Page 19 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

def Success(self, Height, Risk):
                     if Height > self.__MaxFenceHeight:
                         return self.__PercentageSuccess * 0.2
                     else:

                              if Risk == 1:
                                  return self.__PercentageSuccess
                              elif Risk == 2:
                                  return self.__PercentageSuccess * 0.9
                              elif Risk == 3:
                                  return self.__PercentageSuccess * 0.8
                              elif Risk == 4:
                                  return self.__PercentageSuccess * 0.7
                              else:
                                  return self.__PercentageSuccess * 0.6

Mark points

  • Method header taking 2 parameters (and end where appropriate, returning real)
  • Checking if fence height parameter is more than max attribute for that horse, if true multiplying percentage success by
  • (Otherwise) selection checking risk value parameter between 1 and 5, multiplying modifier by percentage success
  • Returning correct value as a real number in all instances
  • Correct use of attributes and parameters throughout

Part 2(d) — solution

  1. If Risk = 1 Then
  2. ElseIf Risk = 2 Then
  3. ElseIf Risk = 3 Then
  4. ElseIf Risk = 4 Then

Mark points

  • If Risk = 1 Then
  • ElseIf Risk = 2 Then
  • ElseIf Risk = 3 Then
  • ElseIf Risk = 4 Then

Part 2(e)(i) — solution

  1. Calling Success() for each horse with the height and risk of all 4 fences …
  2. … using get methods for height and risk of each fence
  3. … outputting the horse name, fence number and calculated success at fence in appropriate message

Visual Basic (VB.NET)

Dim Chance As Single
                        For y = 0 To 1
                             For x = 0 To 3
                                  Chance = Horses(y).Success(Course(x).GetHeight(), Course(x).GetRisk())
                                  Console.WriteLine(Horses(y).GetName() & " Fence " & x + 1 & " chance of
                success is " & Chance & "%")
                             Next
                        Next

Python

for y in range(0, 2):
                     for x in range(0, 4):
                         Chance = Horses[y].Success(Course[x].GetHeight(), Course[x].GetRisk())
                         print(Horses[y].GetName(), "Fence", x + 1, "chance of success is", Chance, "%")

Mark points

  • Calling Success() for each horse with the height and risk of all 4 fences …
  • … using get methods for height and risk of each fence
  • … outputting the horse name, fence number and calculated success at fence in appropriate message

Part 2(e)(ii) — solution

  1. Calculating average of all 4 fences for each horse and outputting in suitable message
  2. Identifying the highest percentage of success and outputting the horse's name in an appropriate message

Python

AverageSuccess = []
                for y in range(0, 2):
                     Total = 0
                     for x in range(0, 4):
                         Chance = Horses[y].Success(Course[x].GetHeight(), Course[x].GetRisk())
                         print(Horses[y].GetName(), "Fence", x + 1, "chance of success is", Chance, "%")
                         Total = Total + Chance
                     Average = Total / 4
                     AverageSuccess.append(Average)
                     print(Horses[y].GetName(), "average success rate is", Average, "%")

                Highest = AverageSuccess[0]
                Winner = -1
                for x in range(1,2):
                    if Highest < AverageSuccess[x]:
                        Winner = x
                        Highest = AverageSuccess[x]
                print(Horses[Winner].GetName(), " has the highest average chance of success ")

 University Press & Assessment 2024                       Page 22 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Calculating average of all 4 fences for each horse and outputting in suitable message
  • Identifying the highest percentage of success and outputting the horse's name in an appropriate message

Part 2(e)(ii) — solution

  1. For y = 0 To 1
  2. Total = 0
  3. For x = 0 To 3
  4. Chance = Horses(y).Success(Course(x).GetHeight(), Course(x).GetRisk())
  5. Total = Total + Chance
  6. Average = Total / 4
  7. AverageSuccess(y) = Average
  8. Highest = AverageSuccess(0)
  9. Winner = -1
  10. For x = 1 To 1
  11. Winner = x
  12. Highest = AverageSuccess(x)

Visual Basic (VB.NET)

Dim Total As Integer
                Dim Chance As Single
                Dim Average As Single
                For y = 0 To 1
                     Total = 0
                     For x = 0 To 3
                          Chance = Horses(y).Success(Course(x).GetHeight(), Course(x).GetRisk())
                          Console.WriteLine(Horses(y).GetName() & " Fence " & x + 1 & " chance of success is
                " & Chance & "%")
                          Total = Total + Chance
                          Average = Total / 4
                          AverageSuccess(y) = Average
                          Console.WriteLine(Horses(y).GetName() & " average success rate is " & Average &
                "%")
                     Next
                Next

                Dim Highest As Single
                Dim Winner As Integer
                Highest = AverageSuccess(0)
                Winner = -1
                For x = 1 To 1
                    If Highest < AverageSuccess(x) Then
                        Winner = x
                        Highest = AverageSuccess(x)
                       End If
                Next x
                Console.WriteLine(Horses(Winner).GetName() & " has the highest average chance of success ")

 University Press & Assessment 2024                       Page 23 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • For y = 0 To 1
  • Total = 0
  • For x = 0 To 3
  • Chance = Horses(y).Success(Course(x).GetHeight(), Course(x).GetRisk())
  • Total = Total + Chance
  • Average = Total / 4
  • AverageSuccess(y) = Average
  • Highest = AverageSuccess(0)
  • Winner = -1
  • For x = 1 To 1
  • Winner = x
  • Highest = AverageSuccess(x)

Part 2(e)(ii) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 2(e)(iii) — solution

  1. Outputting showing correct input values for all fences, and correct chance for each horse on each jump
  2. Outputs of average chance of each horse and horse name with highest average

Mark points

  • Outputting showing correct input values for all fences, and correct chance for each horse on each jump
  • Outputs of average chance of each horse and horse name with highest average

Question 3

Paper page 12 for Q3
Original paper page 12

Part 3(a) — solution

  1. LinkedList declared as 2D array with (min) 20  2 elements (Integer) with all data initialised to -1, all nodes linked
  2. (Global) FirstNode (Int) initialised as -1 and (global) FirstEmpty (Int) initialised as 0

Visual Basic (VB.NET)

Dim LinkedList(20, 2) As Integer
                Dim FirstNode As Integer
                Dim FirstEmpty As Integer

                Sub Main(args As String())
                        FirstNode = -1
                        FirstEmpty = 0
                        For x = 0 To 18
                            LinkedList(x, 0) = -1
                            LinkedList(x, 1) = x + 1

                              Next
                              LinkedList(19, 0) = -1
                              LinkedList(19, 1) = -1
                End Sub

 University Press & Assessment 2024                        Page 26 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • LinkedList declared as 2D array with (min) 20  2 elements (Integer) with all data initialised to -1, all nodes linked
  • (Global) FirstNode (Int) initialised as -1 and (global) FirstEmpty (Int) initialised as 0

Part 3(a) — solution

  1. LinkedList = [] #global
  2. FirstNode = -1
  3. FirstEmpty = 0
  4. LinkedList[19][0] = -1
  5. LinkedList[19][1] = -1

Python

LinkedList = [] #global
                FirstNode = -1
                FirstEmpty = 0
                for x in range(0, 19):
                     LinkedList.append([-1, x + 1])
                LinkedList[19][0] = -1
                LinkedList[19][1] = -1

Mark points

  • LinkedList = [] #global
  • FirstNode = -1
  • FirstEmpty = 0
  • LinkedList[19][0] = -1
  • LinkedList[19][1] = -1

Part 3(b) — solution

  1. Procedure header (and end) taking (min) 5 data items as input from the user
  2. Checking if linked list is full (FirstEmpty = -1) …
  3. …ending procedure/loop/not doing anything further
  4. (otherwise) LinkedList[FirstEmpty, 0] = data input
  5. LinkedList[FirstEmpty, 1] = FirstNode
  6. FirstNode = FirstEmpty
  7. FirstEmpty = LinkedList[FirstEmpty, 1] before any update to FirstEmpty ‘s pointer

Python

def InsertData():
                     global LinkedList
                     global FirstNode
                     global FirstEmpty
                     for _ in range(5):
                         if FirstEmpty != -1:
                             nextEmpty = LinkedList[FirstEmpty][1]
                             LinkedList[FirstEmpty][0] = int(input("Value: "))
                             LinkedList[FirstEmpty][1] = FirstNode
                             FirstNode = FirstEmpty
                             FirstEmpty = nextEmpty

 University Press & Assessment 2024                       Page 28 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Procedure header (and end) taking (min) 5 data items as input from the user
  • Checking if linked list is full (FirstEmpty = -1) …
  • …ending procedure/loop/not doing anything further
  • (otherwise) LinkedList[FirstEmpty, 0] = data input
  • LinkedList[FirstEmpty, 1] = FirstNode
  • FirstNode = FirstEmpty
  • FirstEmpty = LinkedList[FirstEmpty, 1] before any update to FirstEmpty ‘s pointer

Part 3(b) — solution

  1. For x = 0 To 4
  2. NewItem = Console.ReadLine()
  3. If FirstEmpty = -1 Then
  4. x = 5
  5. NextEmpty = LinkedList(FirstEmpty, 1)
  6. LinkedList(FirstEmpty, 0) = NewItem
  7. LinkedList(FirstEmpty, 1) = FirstNode
  8. FirstNode = FirstEmpty
  9. FirstEmpty = NextEmpty

Visual Basic (VB.NET)

Sub InsertData()
                    Dim NewItem As Integer
                    Dim NextEmpty As Integer

                       For x = 0 To 4
                           Console.WriteLine("Enter the next number")
                           NewItem = Console.ReadLine()

                              If FirstEmpty = -1 Then
                                   x = 5
                              Else
                                   NextEmpty = LinkedList(FirstEmpty, 1)
                                   LinkedList(FirstEmpty, 0) = NewItem
                                   LinkedList(FirstEmpty, 1) = FirstNode
                                   FirstNode = FirstEmpty
                                   FirstEmpty = NextEmpty
                              End If

                    Next x
                End Sub

 University Press & Assessment 2024                       Page 29 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • For x = 0 To 4
  • NewItem = Console.ReadLine()
  • If FirstEmpty = -1 Then
  • x = 5
  • NextEmpty = LinkedList(FirstEmpty, 1)
  • LinkedList(FirstEmpty, 0) = NewItem
  • LinkedList(FirstEmpty, 1) = FirstNode
  • FirstNode = FirstEmpty
  • FirstEmpty = NextEmpty

Part 3(b) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(c)(i) — solution

  1. Procedure header (and end) starting with node at index FirstNode and outputting data
  2. Following pointers until end reached and outputting data for each node

Visual Basic (VB.NET)

Sub OutputLinkedList()

                              Dim CurrentPointer As Integer = FirstNode
                              Dim Flag As Boolean = True
                              While Flag
                                  Console.WriteLine(LinkedList(CurrentPointer, 0))
                                  CurrentPointer = LinkedList(CurrentPointer, 1)
                                  If CurrentPointer = -1 Then
                                      Flag = False
                                  End If
                              End While

 University Press & Assessment 2024                       Page 31 of 37

9618/43                                           Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

def OutputLinkedList():
                     global LinkedList
                     global FirstNode
                     global FirstEmpty
                     CurrentPointer = FirstNode
                     Flag = True
                     while Flag:
                         print(LinkedList[CurrentPointer][0])
                         CurrentPointer = LinkedList[CurrentPointer][1]
                         if CurrentPointer == -1:
                             Flag = False

Mark points

  • Procedure header (and end) starting with node at index FirstNode and outputting data
  • Following pointers until end reached and outputting data for each node

Part 3(c)(ii) — solution

1 mark for calling InsertData() then OutputLinkedList() 1 Python InsertData() OutputLinkedList() VB.NET InsertData() OutputLinkedList()

Visual Basic (VB.NET)

InsertData()
                OutputLinkedList()

Python

InsertData()
                OutputLinkedList()

Mark points

  • Include the ideas shown in the solution above.

Part 3(c)(iii) — solution

1 mark for inputs of 5 1 2 3 8 and output of 8 3 2 1 5 1 University Press & Assessment 2024 Page 32 of 37 9618/43 Cambridge International AS & A Level – Mark Scheme October/November 2024

Mark points

  • Include the ideas shown in the solution above.

Part 3(d)(i) — solution

  1. Procedure header (and end) with parameter
  2. Checking data in FirstNode against parameter …
  3. … (if found) updating FirstNode to LinkedList[FirstNode, 1]
  4. (Otherwise) following pointers in loop/recursive call …
  5. …comparing to data to remove each time
  6. … storing previous pointer through each loop…
  7. … when found, updating previous pointer to found node’s pointer
  8. Adding deleted node to end of/start of empty list (and updating FirstEmpty if needed)

Python

def RemoveData(ItemToRemove):
                     global LinkedList
                     global FirstNode
                     global FirstEmpty

                       if LinkedList[FirstNode][0] == ItemToRemove:
                           NewFirst = LinkedList[FirstNode][1]
                           LinkedList[FirstNode][1] = FirstEmpty
                           FirstEmpty = FirstNode
                           FirstNode = NewFirst

                       else:
                           if FirstNode != -1:
                               CurrentPointer = FirstNode
                               PreviousNode = -1
                               while(ItemToRemove != LinkedList[CurrentPointer][0] and CurrentPointer != -1):
                                       PreviousNode = CurrentPointer
                                       CurrentPointer = LinkedList[CurrentPointer][1]

                                    if ItemToRemove == LinkedList[CurrentPointer][0]:
                                        LinkedList[PreviousNode][1] = LinkedList[CurrentPointer][1]
                                        LinkedList[CurrentPointer][0] = -1
                                        LinkedList[CurrentPointer][1] = FirstEmpty
                                        FirstEmpty = CurrentPointer

 University Press & Assessment 2024                       Page 33 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Mark points

  • Procedure header (and end) with parameter
  • Checking data in FirstNode against parameter …
  • … (if found) updating FirstNode to LinkedList[FirstNode, 1]
  • (Otherwise) following pointers in loop/recursive call …
  • …comparing to data to remove each time
  • … storing previous pointer through each loop…
  • … when found, updating previous pointer to found node’s pointer
  • Adding deleted node to end of/start of empty list (and updating FirstEmpty if needed)

Part 3(d)(i) — solution

  1. If LinkedList(FirstNode, 0) = ItemToRemove Then
  2. Dim NewFirst As Integer = LinkedList(FirstNode, 1)
  3. LinkedList(FirstNode, 1) = FirstEmpty
  4. FirstEmpty = FirstNode
  5. FirstNode = NewFirst
  6. Dim CurrentPointer As Integer = FirstNode
  7. Dim PreviousNode As Integer = -1
  8. Dim Flag As Boolean = True
  9. Dim Found As Boolean = False
  10. PreviousNode = CurrentPointer
  11. CurrentPointer = LinkedList(CurrentPointer, 1)
  12. Found = True
  13. Flag = False
  14. LinkedList(PreviousNode, 1) = LinkedList(CurrentPointer, 1)
  15. LinkedList(CurrentPointer, 0) = -1
  16. LinkedList(CurrentPointer, 1) = FirstEmpty
  17. FirstEmpty = CurrentPointer

Visual Basic (VB.NET)

Sub RemoveData(ItemToRemove)
                    If LinkedList(FirstNode, 0) = ItemToRemove Then
                         Dim NewFirst As Integer = LinkedList(FirstNode, 1)
                         LinkedList(FirstNode, 1) = FirstEmpty
                         FirstEmpty = FirstNode
                         FirstNode = NewFirst
                    Else
                         If FirstNode <> -1 Then
                             Dim CurrentPointer As Integer = FirstNode
                             Dim PreviousNode As Integer = -1
                             Dim Flag As Boolean = True
                             Dim Found As Boolean = False
                             While Flag And Not (Found)
                                 If (CurrentPointer <> -1) Then
                                      If (ItemToRemove <> LinkedList(CurrentPointer, 0)) Then
                                           PreviousNode = CurrentPointer
                                           CurrentPointer = LinkedList(CurrentPointer, 1)
                                      Else
                                           Found = True
                                      End If
                                 Else
                                      Flag = False
                                 End If
                             End While

                            If Found Then
                                LinkedList(PreviousNode, 1) = LinkedList(CurrentPointer, 1)
                                LinkedList(CurrentPointer, 0) = -1
                                LinkedList(CurrentPointer, 1) = FirstEmpty
                                FirstEmpty = CurrentPointer
                            End If
                        End If
                    End If
                End Sub

 University Press & Assessment 2024                       Page 34 of 37

9618/43                                            Cambridge International AS & A Level – Mark Scheme           October/November 2024

Mark points

  • If LinkedList(FirstNode, 0) = ItemToRemove Then
  • Dim NewFirst As Integer = LinkedList(FirstNode, 1)
  • LinkedList(FirstNode, 1) = FirstEmpty
  • FirstEmpty = FirstNode
  • FirstNode = NewFirst
  • Dim CurrentPointer As Integer = FirstNode
  • Dim PreviousNode As Integer = -1
  • Dim Flag As Boolean = True
  • Dim Found As Boolean = False
  • PreviousNode = CurrentPointer
  • CurrentPointer = LinkedList(CurrentPointer, 1)
  • Found = True
  • Flag = False
  • LinkedList(PreviousNode, 1) = LinkedList(CurrentPointer, 1)
  • LinkedList(CurrentPointer, 0) = -1
  • LinkedList(CurrentPointer, 1) = FirstEmpty
  • FirstEmpty = CurrentPointer

Part 3(d)(i) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(d)(ii) — solution

  1. LinkedList = []
  2. FirstNode = -1
  3. FirstEmpty = 0
  4. FirstNode = -1
  5. FirstEmpty = 0
  6. For x = 0 To 19
  7. LinkedList(x, 0) = -1
  8. LinkedList(x, 1) = x + 1

Visual Basic (VB.NET)

Sub Main(args As String())
                    FirstNode = -1
                    FirstEmpty = 0
                    For x = 0 To 19
                         LinkedList(x, 0) = -1
                         LinkedList(x, 1) = x + 1
                    Next
                    InsertData()
                    OutputLinkedList()
                    RemoveData(5)
                    Console.WriteLine("After")
                    OutputLinkedList()
                End Sub

 University Press & Assessment 2024                       Page 36 of 37

9618/43                                          Cambridge International AS & A Level – Mark Scheme   October/November 2024

Python

LinkedList = []
                FirstNode = -1
                FirstEmpty = 0
                for x in range(0, 19):
                     LinkedList.append([-1, x + 1])
                InsertData()
                OutputLinkedList()
                RemoveData(5)
                print("After")
                OutputLinkedList()

Mark points

  • LinkedList = []
  • FirstNode = -1
  • FirstEmpty = 0
  • FirstNode = -1
  • FirstEmpty = 0
  • For x = 0 To 19
  • LinkedList(x, 0) = -1
  • LinkedList(x, 1) = x + 1

Part 3(d)(ii) — solution

Mark points

  • Include the ideas shown in the solution above.

Part 3(d)(iii) — solution

1 mark for input and output. 1 Test data 1: Input 5 6 8 9 5 ‘After’ Output: 9 8 6 5 Test data 2: Input 10 7 8 5 6 “After” Output: 6 8 7 10 University Press & Assessment 2024 Page 37 of 37

Mark points

  • Include the ideas shown in the solution above.