Cambridge International AS & A Level: Computer Science 9618/41
Cambridge International AS & A Level: Computer Science 9618/41
Published
This mark scheme is published as an aid to teachers and candidates, to indicate the requirements of the
examination. It shows the basis on which Examiners were instructed to award marks. It does not indicate the
details of the discussions that took place at an Examiners’ meeting before marking began, which would have
considered the acceptability of alternative answers.
Mark schemes should be read in conjunction with the question paper and the Principal Examiner Report for
Teachers.
Cambridge International will not enter into discussions about these mark schemes.
Cambridge International is publishing the mark schemes for the October/November 2024 series for most
Cambridge IGCSE, Cambridge International A and AS Level components, and some Cambridge O Level
components.
These general marking principles must be applied by all examiners when marking candidate answers. They should be applied alongside the
specific content of the mark scheme or generic level descriptions for a question. Each question paper and mark scheme will also comply with these
marking principles.
• the specific content of the mark scheme or the generic level descriptors for the question
• the specific skills defined in the mark scheme or in the generic level descriptors for the question
• the standard of response required by a candidate as exemplified by the standardisation scripts.
Marks awarded are always whole marks (not half marks, or other fractions).
• marks are awarded for correct/valid answers, as defined in the mark scheme. However, credit is given for valid answers which go beyond
the scope of the syllabus and mark scheme, referring to your Team Leader as appropriate
• marks are awarded when candidates clearly demonstrate what they know and can do
• marks are not deducted for errors
• marks are not deducted for omissions
• answers should only be judged on the quality of spelling, punctuation and grammar when these features are specifically assessed by the
question as indicated by the mark scheme. The meaning, however, should be unambiguous.
Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level
descriptors.
Marks should be awarded using the full range of marks defined in the mark scheme for the question (however; the use of the full mark range may
be limited according to the quality of the candidate responses seen).
Marks awarded are based solely on the requirements as defined in the mark scheme. Marks should not be awarded with grade thresholds or
grade descriptors in mind.
e.g.
Python
def ReadData():
Colours = []
try:
File = open("Data.txt")
Colours = File.read().split("\n")
File.close()
return Colours
except:
print("No file found")
VB.NET
Function ReadData()
Dim TextFile As String = "Data.txt"
1(a) Next
FileReader.Close()
Catch ex As Exception
Console.WriteLine("No file found")
End Try
Return Colours
End Function
Java
public static String[] ReadData(){
String TextFile = "Data.txt";
String Colours[] = new String[45];
try{
FileReader f = new FileReader(TextFile);
BufferedReader Reader = new BufferedReader(f);
for(Integer X = 0; X < 45; X++){
try{
Colours[X] = Reader.readLine();
}catch(IOException ex){}
}
try{
Reader.close();
}catch(IOException ex){}
return Colours;
}catch(FileNotFoundException e){
System.out.println("File not found");
}
return Colours;
}
Python
def FormatArray(DataArray):
OutputText = ""
for x in range(0, 45):
OutputText = OutputText + DataArray[x] + " "
return OutputText
VB.NET
Function FormatArray(DataArray)
Dim OutputText As String = ""
For X = 0 To 44
OutputText = OutputText & DataArray(X) & " "
Next
Return OutputText
End Function
Java
public static String FormatArray(String[] DataArray){
String OutputText = "";
for(Integer X = 0; X < 45; X++){
OutputText = OutputText + DataArray[X] + " ";
}
return OutputText;
}
Python
Colours = ReadData() #string array
print(FormatArray(Colours))
VB.NET
Dim Colours(45) As String
Colours = ReadData()
Console.WriteLine(FormatArray(Colours))
Java
String[] Colours = new String[45];
Colours = ReadData();
System.out.println(FormatArray(Colours));
e.g.
e.g.
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
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
1(c) Java
public static Integer CompareStrings(String First, String Second){
Integer Count = 0;
while(true){
if(First.substring(Count, Count + 1).compareTo(Second.substring(Count, Count +
1)) < 0){
return 1;
}else if(First.substring(Count, Count + 1).compareTo(Second.substring(Count,
Count + 1))>0){
return 2;
}else{
Count++;
}
}
}
Python
def Bubble(DataArray):
ArrayLength = len(DataArray)
1(d)(i) 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
Java
public static String[] Bubble(String[] DataArray){
Integer ArrayLength = 45;
Integer Result;
String Temp;
for(Integer X = 0; X < ArrayLength ; X++){
for(Integer Y = 0; Y < ArrayLength - X - 1; Y++){
Result = CompareStrings(DataArray[Y], DataArray[Y+1]);
Python
BubbleSorted = Bubble(Colours)
print(FormatArray(BubbleSorted))
VB.NET
Dim BubbleSorted(45) As String
BubbleSorted = Bubble(Colours)
Console.WriteLine(FormatArray(BubbleSorted))
Java
String[] BubbleSorted = new String[45];
BubbleSorted = Bubble(Colours);
System.out.println(FormatArray(BubbleSorted));
e.g.
e.g.
Python
class Horse:
def __init__(self, PName, PMaxFenceHeight, PPercentageSuccess):
self.__Name = PName #String
self.__MaxFenceHeight = PMaxFenceHeight #Integer
self.__PercentageSuccess = PPercentageSuccess #Integer
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
2(a)(i) Java
class Horse{
private static String Name;
private static Integer MaxFenceHeight;
private static Integer PercentageSuccess;
}
}
e.g.
Python
def GetName(self):
return self.__Name
def GetMaxFenceHeight(self):
return self.__MaxFenceHeight
VB.NET
Function GetName()
Return Name
End Function
Java
public String GetName(){
return Name;
}
public Integer GetMaxFenceHeight(){
return MaxFenceHeight;
}
e.g.
Python
Horses = []
Horses.append(Horse("Beauty", 150, 72))
Horses.append(Horse("Jet", 160, 65))
print(Horses[0].GetName())
print(Horses[1].GetName())
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())
2(b)(i) Java
Horse[] Horses = new Horse[2];
Horses[0] = new Horse("Beauty", 150, 72);
Horses[1] = new Horse("Jet", 160, 65);
System.out.println(Horses[0].GetName());
System.out.println(Horses[1].GetName());
e.g.
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
2(c)(i) VB.NET
Class Fence
Dim Height As Integer
Dim Risk As Integer
Function GetRisk()
Return Risk
End Function
End Class
Java
class Fence{
private Integer Height;
private Integer Risk;
e.g.
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))
2(c)(ii) 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
Java
Fence [] Course = new Fence [4];
for(Integer x = 0; x < 4; x++){
do {
System.out.println("Enter the height in cm");
Height = Integer.parseInt(scanner.nextLine());
} while(Height <70 || Height > 180);
do{
System.out.println("Enter the risk between 1 (easy) and 5 (hard)");
Risk = Integer.parseInt(scanner.nextLine());
}while(Risk <1 || Risk > 5);
Course[x] = new Fence(Height, Risk);
}
e.g.
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
VB.NET
Function Success(Height, Risk)
If Height > MaxFenceHeight Then
Return PercentageSuccess * 0.2
Else
End Function
Java
public static Double Success(Integer Height, Integer Risk){
if(Height > MaxFenceHeight){
return Double.valueOf(PercentageSuccess) * 0.2;
}else{
if(Risk == 1){
return Double.valueOf(PercentageSuccess);
}else if (Risk == 2){
return Double.valueOf(PercentageSuccess) * 0.9;
}else if (Risk == 3){
return Double.valueOf(PercentageSuccess) * 0.8;
}else if (Risk == 4){
return Double.valueOf(PercentageSuccess) * 0.7;
}else{
return Double.valueOf(PercentageSuccess) * 0.6;
}
}
}
e.g.
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, "%")
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
Java
Double Chance = 0.0;
for(Integer y = 0; y < 2; y ++){
for(Integer x = 0; x < 4; x++){
Chance = Horses[y].Success(Course[x].GetHeight(), Course[x].GetRisk());
System.out.println(Horses[y].GetName() + " Fence " + (x + 1) + " chance of
success is " + Chance + "%");
}
}
e.g.
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 ")
2(e)(ii) 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
2(e)(ii) Java
Double Total = 0.0;
Double Chance = 0.0;
Double Average = 0.0;
for(Integer y = 0; y < 2; y ++){
Total = 0.0;
for(Integer x = 0; x < 4; x++){
Chance = Horses[y].Success(Course[x].GetHeight(), Course[y].GetRisk());
System.out.println(Horses[y].GetName() + " Fence " + (x + 1) + " chance of
success is " + Chance + "%");
Total = Total + Chance;
}
Average = Total / 4;
AverageSuccess[y] = Average;
System.out.println(Horses[y].GetName() + " average success rate is " + Average +
"%");
}
Double Highest = AverageSuccess[0];
Integer Winner = 0;
for(Integer x = 1; x < 2; x++){
if(Highest < AverageSuccess[x]){
Winner = x;
Highest = AverageSuccess[x];
}
}
System.out.println(Horses[Winner].GetName() + " has the highest average chance of
success");
e.g.
VB.NET
Dim LinkedList(20, 2) As Integer
Dim FirstNode As Integer
Dim FirstEmpty As Integer
Next
LinkedList(19, 0) = -1
LinkedList(19, 1) = -1
End Sub
3(a) 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
Java
private static Integer[][] LinkedList = new Integer[20][2];
private static Integer FirstNode;
private static Integer FirstEmpty;
public static void main(String args[]){
FirstNode = -1;
FirstEmpty = 0;
for(Integer X = 0; X < 19; X++){
LinkedList[X][0] = -1;
LinkedList[X][1] = X + 1;
}
LinkedList[19][0] = -1;
LinkedList[19][1] = -1;
}
e.g.
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
3(b) 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
3(b) Java
public static void InsertData(){
Integer NewItem;
Integer CurrentPointer = 0;
Integer PreviousPointer = 0;
Scanner scanner = new Scanner(System.in);
Integer NextEmpty;
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
VB.NET
Sub OutputLinkedList()
Java
public static void OutputLinkedList(){
Integer CurrentPointer = FirstNode;
Boolean Flag = true;
while(Flag){
System.out.println(LinkedList[CurrentPointer][0]);
CurrentPointer = LinkedList[CurrentPointer][1];
if(CurrentPointer == -1){Flag = false;}
}
}
Python
InsertData()
OutputLinkedList()
VB.NET
InsertData()
OutputLinkedList()
Java
InsertData();
OutputLinkedList();
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
3(d)(i) 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
3(d)(i) Java
public static void RemoveData(Integer ItemToRemove){
Integer CurrentPointer = 0;
Integer PreviousNode = 0;
Integer NewFirst = 0;
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] && 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;
}
}
}
}
Python
LinkedList = []
FirstNode = -1
FirstEmpty = 0
for x in range(0, 19):
LinkedList.append([-1, x + 1])
InsertData()
OutputLinkedList()
RemoveData(5)
print("After")
OutputLinkedList()
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
3(d)(ii) Java
public static void main(String args[]){
FirstNode = -1;
FirstEmpty = 0;
for(Integer X = 0; X < 20; X++){
LinkedList[X][0] = -1;
LinkedList[X][1] = X + 1;
}
InsertData();
OutputLinkedList();
RemoveData(5);
System.out.println("After");
OutputLinkedList();
}
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