Computer Science (9618) · May/June 2024 · Mark scheme 42
Cambridge Computer Science (9618) mark scheme for paper 42, May/June 2024 — 9618/42/M/J/24, file 9618_s24_ms_42.pdf.
Text of this paper
www.dynamicpapers.com
Cambridge International AS & A Level
COMPUTER SCIENCE
9618/42
Paper 4 Practical
May/June 2024
MARK SCHEME
Maximum Mark: 75
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 May/June 2024 series for most
Cambridge IGCSE, Cambridge International A and AS Level and Cambridge Pre-U components, and some
Cambridge O Level components.
This document consists of 50 printed pages.
© Cambridge University Press & Assessment 2024
[Turn over
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Generic Marking Principles
May/June 2024
www.dynamicpapers.com
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.
GENERIC MARKING PRINCIPLE 1:
Marks must be awarded in line with:
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.
GENERIC MARKING PRINCIPLE 2:
Marks awarded are always whole marks (not half marks, or other fractions).
GENERIC MARKING PRINCIPLE 3:
Marks must be awarded positively:
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.
GENERIC MARKING PRINCIPLE 4:
Rules must be applied consistently, e.g. in situations where candidates have not followed instructions or in the application of generic level
descriptors.
© Cambridge University Press & Assessment 2024
Page 2 of 50
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
May/June 2024
www.dynamicpapers.com
GENERIC MARKING PRINCIPLE 5:
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).
GENERIC MARKING PRINCIPLE 6:
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.
© Cambridge University Press & Assessment 2024
Page 3 of 50
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(a)
Answer
1 mark each to max 6
Procedure declaration (and end where appropriate) taking (string) parameter
Declaration of array to store the data read (type string, suitable number of elements e.g. 150)
Opening file to read…
... using exception handling with try and catch and output
Reading in the data for each line in that file and storing in array…
… removing carriage return (Java, Python)
Counting the number of words
Closing the file (might be within the Python opening file statement)
e.g.
Java
public static void ReadWords(String FileName){
try{
FileReader f = new FileReader(FileName);
try{
BufferedReader Reader = new BufferedReader(f);
String Line= Reader.readLine();
while (Line != null){
WordArray[NumberWords] = Line.replace("\n","");
NumberWords++;
Line = Reader.readLine();
}
Reader.close();
}catch(IOException ex){}
© Cambridge University Press & Assessment 2024
Page 4 of 50
May/June 2024
www.dynamicpapers.com
Marks
6
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(a)
Answer
}catch(FileNotFoundException e){
System.out.println("File not found");
}
}
VB.NET
Sub ReadWords(FileName As String)
Try
Dim DataReader As StreamReader = New StreamReader(FileName)
NumberWords = 0
Do Until DataReader.EndOfStream
WordArray(NumberWords) = DataReader.ReadLine()
NumberWords = NumberWords + 1
Loop
DataReader.Close()
Catch ex As Exception
Console.WriteLine("Invalid file")
End Try
End Sub
Python
def ReadWords(FileName):
global WordArray
global NumberWords
File = open(FileName, 'r')
DataRead = File.read().strip()
File.close()
WordArray = DataRead.split()
NumberWords = len(WordArray)
© Cambridge University Press & Assessment 2024
Page 5 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(b)
Answer
1 mark each
Outputting message to ask user to enter easy, medium, hard
Taking input from user
Conversion of input to filename…
… calling ReadWords() with correct filename in each case
e.g.
Java
public static void main(String args[]){
NumberWords = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("Easy, medium or hard?");
String Choice = scanner.nextLine();
if(Choice.equals("Easy")){
ReadWords("Easy.txt");
}else if(Choice.equals("medium")){
ReadWords("Medium.txt");
}else{
ReadWords("Hard.txt");
}
}
VB.NET
Sub Main(args As String())
Console.WriteLine("Easy, medium or hard?")
Dim FileName As String
Dim Choice As String = Console.ReadLine().ToLower()
If Choice = "easy" Then
FileName = "Easy.txt"
ElseIf Choice = "medium" Then
FileName = "Medium.txt"
Else
© Cambridge University Press & Assessment 2024
Page 6 of 50
May/June 2024
www.dynamicpapers.com
Marks
4
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(b)
Answer
FileName = "Hard.txt"
End If
ReadWords(FileName)
End Sub
Python
WordArray = []
NumberWords = 0
Choice = input("Easy, medium or hard? ").lower()
if Choice == "easy":
File = "Easy.txt"
elif Choice == "medium":
File = "Medium.txt"
else:
File = "Hard.txt"
ReadWords(File)
© Cambridge University Press & Assessment 2024
Page 7 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
May/June 2024
www.dynamicpapers.com
Question
Answer
1(c)(i)
1 mark each
Procedure (and end) taking array and number of answers as parameters and outputting the main word and the number
of answers
Loops until user requests to stop (enters "no") ….
… takes word as input and compares input to each answer in array but not the main word
… method of recording answers found e.g. replaces with "" (or appropriate null)
… outputs if found and not found
Counts the number of answers found (in loop, second array, any method)
e.g.
Java
public static void Play(){
System.out.println(NumberWords);
Scanner scanner = new Scanner(System.in);
String WordChosen = WordArray[0];
System.out.println("The word is " + WordChosen);
System.out.println("There are " + NumberWords + " words that can be made with 3 or more
letters");
WordArray[0] = "";
Boolean Contin = true;
Integer QuantityFound = 0;
String WordInput;
Boolean Found = false; String Answer = "yes";
while(!(Answer.equals("no"))){
System.out.println("Enter your word or no to stop");
Answer = scanner.nextLine();
Found = false;
if(!(Answer.equals("no"))){
for(Integer x = 0; x <= NumberWords; x++){
if(Answer.equals(WordArray[x])){
WordArray[x] = "";
© Cambridge University Press & Assessment 2024
Page 8 of 50
Marks
6
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
May/June 2024
www.dynamicpapers.com
Answer
QuantityFound++;
System.out.println("Correct, you have found " + QuantityFound + " words");
Found = true;
1(c)(i)
}
}
if(Found == false){
System.out.println("Sorry that was incorrect");
}
}
}
}
VB.NET
Sub Play()
Dim Word As String = WordArray(0)
Console.WriteLine("The word is: " & Word)
Console.WriteLine("There are " & NumberWords & " words that can be made with 3 or more
letters")
WordArray(0) = ""
Dim Contin As Boolean = True
Dim QuantityFound As Integer = 0
Dim Found As Boolean
Dim Answer As String = "yes"
While Answer <> "no"
Console.WriteLine("Enter your word or no to stop")
Answer = Console.ReadLine().ToLower()
Found = False
If Answer <> "Not" Then
For x = 0 To NumberWords
If Answer = WordArray(x) Then
© Cambridge University Press & Assessment 2024
Page 9 of 50
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
May/June 2024
www.dynamicpapers.com
Answer
WordArray(x) = ""
QuantityFound = QuantityFound + 1
Console.WriteLine("Correct, you have found " & QuantityFound & " words")
Found = True
x = NumberWords + 1
End If
1(c)(i)
Next x
If Found = False Then
Console.WriteLine("Sorry that was incorrect")
End If
End If
End While
End Sub
Python
def Play():
global WordArray
global NumberWords
Word = WordArray[0]
print("The word is: ", Word)
print("There are", NumberWords-1,"words that can be made with 3 or more letters")
WordArray[0] = ""
Answer = "yes"
QuantityFound = 0
while Answer != "no":
Answer = input("Enter your word or no to stop ").lower()
Found = False
© Cambridge University Press & Assessment 2024
Page 10 of 50
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(c)(i)
Answer
if Answer != "no":
for x in range(0, NumberWords):
if Answer == WordArray[x]:
WordArray[x] = ""
QuantityFound = QuantityFound + 1
print("Correct, you have found", QuantityFound, "words")
Found = True
if Found == False:
print("Sorry that was incorrect")
© Cambridge University Press & Assessment 2024
Page 11 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(c)(ii)
May/June 2024
www.dynamicpapers.com
Answer
1 mark each
Calculates and outputs percentage of answers found (when ‘no’ is entered)
Method of identifying answers not found (e.g. looping array and skipping null values)…
… and outputting those answers
e.g.
Java
public static void Play(){
System.out.println(NumberWords);
Scanner scanner = new Scanner(System.in);
String WordChosen = WordArray[0];
System.out.println("The word is " + WordChosen);
System.out.println("There are " + NumberWords + " words that can be made with 3 or
more letters");
WordArray[0] = "";
Boolean Contin = true;
Integer QuantityFound = 0;
String WordInput;
Boolean Found = false;
String Answer = "yes";
while(!(Answer.equals("no"))){
System.out.println("Enter your word or no to stop");
Answer = scanner.nextLine();
Found = false;
if(!(Answer.equals("no"))){
for(Integer x = 0; x <= NumberWords; x++){
if(Answer.equals(WordArray[x])){
WordArray[x] = "";
QuantityFound++;
System.out.println("Correct, you have found " + QuantityFound + "
words");
© Cambridge University Press & Assessment 2024
Page 12 of 50
Marks
3
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
May/June 2024
www.dynamicpapers.com
Answer
Found = true;
1(c)(ii)
}
}
if(Found == false){
System.out.println("Sorry that was incorrect");
}
}
}
double Correct = ((Double.valueOf(QuantityFound) / Double.valueOf(NumberWords)) *
100.0);
System.out.println("You found " + Correct + "%");
if(Correct < 100){
System.out.println("The words you missed are");
for(Integer x = 0; x <= NumberWords; x++){
if(WordArray[x] != ""){
System.out.println(WordArray[x]);
}
}
}
}
VB.NET
Sub Play()
Dim Word As String = WordArray(0)
Console.WriteLine("The word is: " & Word)
Console.WriteLine("There are " & NumberWords & " words that can be made with 3 or more
letters")
© Cambridge University Press & Assessment 2024
Page 13 of 50
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(c)(ii)
May/June 2024
www.dynamicpapers.com
Answer
WordArray(0) = ""
Dim Contin As Boolean = True
Dim QuantityFound As Integer = 0
Dim Found As Boolean
Dim Answer As String = "yes"
While Answer <> "no"
Console.WriteLine("Enter your word or no to stop")
Answer = Console.ReadLine().ToLower()
Found = False
If Answer <> "Not" Then
For x = 0 To NumberWords
If Answer = WordArray(x) Then
WordArray(x) = ""
QuantityFound = QuantityFound + 1
Console.WriteLine("Correct, you have found " & QuantityFound & " words")
Found = True
x = NumberWords + 1
End If
Next x
If Found = False Then
Console.WriteLine("Sorry that was incorrect") End If
End If
End While
Dim Correct As Double
Correct = (QuantityFound / NumberWords) * 100
Console.WriteLine("You found " & Correct & "%")
If Correct < 100 Then
Console.WriteLine("The words you missed are ")
For x = 0 To NumberWords
If WordArray(x) <> "" Then
© Cambridge University Press & Assessment 2024
Page 14 of 50
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(c)(ii)
May/June 2024
www.dynamicpapers.com
Answer
Console.WriteLine(WordArray(x))
End If
Next x
End If
End Sub
Python
def Play():
global WordArray
global NumberWords
Word = WordArray[0]
print("The word is: ", Word)
print("There are", NumberWords-1,"words that can be made with 3 or more letters")
WordArray[0] = ""
Answer = "yes"
QuantityFound = 0
while Answer != "no":
Answer = input("Enter your word or no to stop ").lower()
Found = False
if Answer != "no":
for x in range(0, NumberWords):
if Answer == WordArray[x]:
WordArray[x] = ""
QuantityFound = QuantityFound + 1
print("Correct, you have found", QuantityFound, "words")
Found = True
if Found == False:
print("Sorry that was incorrect")
Correct = (QuantityFound / (NumberWords-1)) * 100
print("You found", Correct,"%")
© Cambridge University Press & Assessment 2024
Page 15 of 50
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(c)(ii)
Answer
if Correct < 100:
print("The words you missed are")
for x in range(0, NumberWords-1):
if WordArray[x] != "":
print(WordArray[x])
© Cambridge University Press & Assessment 2024
Page 16 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(d)(i)
Answer
1 mark for:
Calling Play() with array and number of answers after all read in from file
e.g.
Java
public static void ReadWords(String FileName){
try{
FileReader f = new FileReader(FileName);
try{
BufferedReader Reader = new BufferedReader(f);
String Line= Reader.readLine();
while (Line != null){
WordArray[NumberWords] = Line.replace("\n","");
NumberWords++;
Line = Reader.readLine();
}
Reader.close();
Play();
}catch(IOException ex){}
}catch(FileNotFoundException e){
System.out.println("File not found");
}
}
© Cambridge University Press & Assessment 2024
Page 17 of 50
May/June 2024
www.dynamicpapers.com
Marks
1
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(d)(i)
Answer
VB.NET
Sub ReadWords(FileName As String)
Try
Dim DataReader As StreamReader = New StreamReader(FileName)
NumberWords = 0
Do Until DataReader.EndOfStream
WordArray(NumberWords) = DataReader.ReadLine()
NumberWords = NumberWords + 1
Loop
DataReader.Close()
Play()
Catch ex As Exception
Console.WriteLine("Invalid file")
End Try
End Sub
Python
def ReadWords(FileName):
global WordArray
global NumberWords
File = open(FileName, 'r')
DataRead = File.read().strip()
File.close()
WordArray = DataRead.split()
NumberWords = len(WordArray)
Play()
© Cambridge University Press & Assessment 2024
Page 18 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(d)(ii)
Answer
1 mark for screenshot showing the inputs "easy", "she", "out", "no" e.g.
© Cambridge University Press & Assessment 2024
Page 19 of 50
May/June 2024
www.dynamicpapers.com
Marks
1
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
1(d)(iii)
Answer
1 mark for screenshot showing the inputs ‘hard’, ‘fine’, ‘fined’, ‘idea’, ‘no’ e.g.
© Cambridge University Press & Assessment 2024
Page 20 of 50
May/June 2024
www.dynamicpapers.com
Marks
1
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(a)(i)
Answer
1 mark each to max 4
Class declaration (and end where appropriate) with identifier Node
LeftPointer, Data and RightPointer, integer
Constructor taking 1 parameter (within class) …
… assigning parameter to Data initialising LeftPointer and RightPointer to –1
e.g.
Java
public class Node{
private Integer LeftPointer;
private Integer Data;
private Integer RightPointer;
}
public Node(Integer PData){
LeftPointer = -1;
Data = PData;
RightPointer = -1;
}
VB.NET
Class Node
Private LeftPointer As Integer
Private Data As Integer
Private RightPointer As Integer
Sub New(PData)
LeftPointer = -1
Data = PData
RightPointer = -1
End Sub
End Class
© Cambridge University Press & Assessment 2024
Page 21 of 50
May/June 2024
www.dynamicpapers.com
Marks
4
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(a)(i)
Answer
Python
class Node():
def
init (self, PData):
self. LeftPointer = -1 #int
self. Data = PData #int
self. RightPointer = -1 #int
© Cambridge University Press & Assessment 2024
Page 22 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(a)(ii)
Answer
1 mark each
1 get method with no parameter…
…returning correct attribute
Remaining 2 correct (FT minor errors)
Marks
3
e.g.
Java
public Integer GetLeft(){
return LeftPointer;
}
public Integer GetRight(){
return RightPointer;
}
public Integer GetData(){
return Data;
}
VB.NET
Function GetLeft()
Return LeftPointer
End Function
Function GetRight()
Return RightPointer
End Function
Function GetData()
Return Data
End Function
Python
def GetLeft(self):
return self. LeftPointer
© Cambridge University Press & Assessment 2024
May/June 2024
www.dynamicpapers.com
Page 23 of 50
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(a)(ii)
Answer
def GetRight(self):
return self. RightPointer
def GetData(self):
return self. Data
© Cambridge University Press & Assessment 2024
Page 24 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(a)(iii)
Answer
Marks
3
1 mark each
1 set method with parameter …
… assigning to attribute
Remaining 2 correct (FT minor errors)
e.g.
Java
public void SetLeft(Integer NewLeft){
LeftPointer = NewLeft;
}
public void SetRight(Integer NewRight){
RightPointer = NewRight;
}
public void SetData(Integer NewData){
Data = NewData;
}
VB.NET
Sub SetLeft(NewLeft)
LeftPointer = NewLeft
End Sub
Sub SetRight(NewRight)
RightPointer = NewRight
End Sub
Sub SetData(NewData)
Data = NewData
End Sub
Python
def SetLeft(self, NewLeft):
self. LeftPointer = NewLeft
def SetRight(self, NewRight):
© Cambridge University Press & Assessment 2024
May/June 2024
www.dynamicpapers.com
Page 25 of 50
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(a)(iii)
Answer
self. RightPointer = NewRight
def SetData(self, NewData):
self. Data = NewData
© Cambridge University Press & Assessment 2024
Page 26 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(b)(i)
May/June 2024
www.dynamicpapers.com
Answer
1 mark each
Class header (and end)
Private array Tree of type Node with 20 elements, private FirstNode and private NumberNodes
Constructor assigns –1 to FirstNode and 0 to NumberNodes
… initialises all Tree (20) elements to Node object with data value –1
e.g.
Java
class TreeClass{
private static Node[] Tree = new Node[20];
private static Integer FirstNode;
private static Integer NumberNodes;
public TreeClass(){
FirstNode = -1;
NumberNodes = 0;
Integer MinusOne = -1;
for(Integer x = 0; x < 20; x++){
Tree[x] = new Node(MinusOne);
}
}
}
VB.NET
Class TreeClass
Private Tree(20) As Node
Private FirstNode As Integer
Private NumberNodes As Integer
Sub New()
FirstNode = -1
NumberNodes = 0
© Cambridge University Press & Assessment 2024
Page 27 of 50
Marks
4
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(b)(i)
Answer
For x = 0 To 19
Tree(x) = New Node(-1)
Next
End Sub
End Class
Python
class TreeClass():
def
init (self):
self. Tree = [] #type node 20 spaces
self. FirstNode = -1 #int
self. NumberNodes = 0 #int
for x in range(20):
self. Tree.append(Node(-1))
© Cambridge University Press & Assessment 2024
Page 28 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(b)(ii)
May/June 2024
www.dynamicpapers.com
Answer
1 mark each:
Method header and end, taking node as parameter and checking if empty and inserting in first position, updating
FirstNode
… otherwise inserting node in tree
Accessing first node and comparing data …
… checking whether to go left or right …
… repeatedly until data found
Updating left and right pointer for parent node
e.g.
Java
public void InsertNode(Node NewNode){
Integer NodeAccess;
Integer Previous = -1;
String Direction;
if(NumberNodes == 0){
Tree[0] = NewNode;
FirstNode = 0;
NumberNodes++;
}else{
Tree[NumberNodes] = NewNode;
NodeAccess = FirstNode;
Direction = "";
System.out.println(Tree[0].GetData());
while(NodeAccess != -1){
Previous = NodeAccess;
if(NewNode.GetData() < Tree[NodeAccess].GetData()){
NodeAccess = Tree[NodeAccess].GetLeft();
Direction = "left";
© Cambridge University Press & Assessment 2024
Page 29 of 50
Marks
6
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
Answer
}else if(NewNode.GetData() > Tree[NodeAccess].GetData()){
NodeAccess = Tree[NodeAccess].GetRight();
Direction = "right";
}
2(b)(ii)
}
if(Direction.equals("left")){
Tree[Previous].SetLeft(NumberNodes);
}else{
Tree[Previous].SetRight(NumberNodes);
}
NumberNodes++;
}
}
VB.NET
Sub InsertNode(NewNode)
Dim NodeAccess As Integer
Dim Direction As String
Dim Previous As Integer
If NumberNodes = 0 Then
Tree(0) = NewNode
FirstNode = 0
NumberNodes += 1
Else
Tree(NumberNodes) = NewNode
NodeAccess = FirstNode
Direction = ""
While NodeAccess <> -1
Previous = NodeAccess
© Cambridge University Press & Assessment 2024
Page 30 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
Answer
If NewNode.GetData() < Tree(NodeAccess).GetData() Then
NodeAccess = Tree(NodeAccess).GetLeft()
Direction = "left"
ElseIf NewNode.GetData() > Tree(NodeAccess).GetData() Then
NodeAccess = Tree(NodeAccess).GetRight()
Direction = "right"
End If
End While
2(b)(ii)
If Direction = "left" Then
Tree(Previous).SetLeft(NumberNodes)
Else
Tree(Previous).SetRight(NumberNodes)
End If
NumberNodes += 1
End If
End Sub
Python
def InsertNode(self, NewNode):
if(self.
NumberNodes == 0):
self. Tree[0] = NewNode self. FirstNode = 0
self. NumberNodes = self. NumberNodes + 1
else:
self. Tree[self. NumberNodes] = NewNode
NodeAccess = self. FirstNode
Direction = ""
while(NodeAccess != -1):
Previous = NodeAccess
if NewNode.GetData() < self.
© Cambridge University Press & Assessment 2024
Tree[NodeAccess].GetData():
Page 31 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(b)(ii)
Answer
NodeAccess = self. Tree[NodeAccess].GetLeft()
Direction = "left"
elif NewNode.GetData() > self. Tree[NodeAccess].GetData():
NodeAccess = self. Tree[NodeAccess].GetRight()
Direction = "right"
if(Direction == "left"):
self. Tree[Previous].SetLeft(self. NumberNodes)
else:
self. Tree[Previous].SetRight(self. NumberNodes)
self. NumberNodes = self. NumberNodes + 1
© Cambridge University Press & Assessment 2024
Page 32 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(b)(iii)
May/June 2024
www.dynamicpapers.com
Answer
1 mark each
Procedure header (and end) with no parameter and if no nodes output ‘No nodes’
(otherwise) Loop from index 0 to NumberNodes (or equivalent) …
… Outputting LeftPointer, Data then RightPointer
… using get methods
e.g.
Java
public void OutputTree(){
if(NumberNodes == 0){
System.out.println("No nodes");
}else{
for(Integer x = 0; x < NumberNodes; x++){
System.out.println(Tree[x].GetLeft() + " " + Tree[x].GetData() + " " +
Tree[x].GetRight());
}
}
}
VB.NET
Sub OutputTree()
If NumberNodes = 0 Then
Console.WriteLine("No nodes")
Else
For x = 0 To NumberNodes - 1
Console.WriteLine(Tree(x).GetLeft() & " " & Tree(x).GetData() & " " &
Tree(x).GetRight())
Next
End If
End Sub
© Cambridge University Press & Assessment 2024
Page 33 of 50
Marks
4
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(b)(iii)
Answer
Marks
Python
def OutputTree(self):
if self. NumberNodes == 0:
print("No nodes")
else:
for x in range(0, self. NumberNodes):
print(self. Tree[x].GetLeft(), " ", self.
Tree[x].GetRight())
2(c)(i)
May/June 2024
www.dynamicpapers.com
1 mark for
Instance of TreeClass created with identifier TheTree
e.g.
Java
public static void main(String args[]){
TreeClass TheTree = new TreeClass();
}
VB.NET
Sub Main(args As String())
Dim TheTree As TreeClass = New TreeClass()
End Sub
Python
TheTree = TreeClass()
© Cambridge University Press & Assessment 2024
Page 34 of 50
Tree[x].GetData(), " ",self.
1
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(c)(ii)
Answer
1 mark each
Creating one node with one correct value (e.g. 10)
Calling InsertNode for TheTree with each new Node
All nodes correctly assigned in order
Calling OutputTree
e.g.
Java
public static void main(String args[]){
TreeClass TheTree = new TreeClass();
TheTree.InsertNode(new
TheTree.InsertNode(new
TheTree.InsertNode(new
TheTree.InsertNode(new
TheTree.InsertNode(new
TheTree.InsertNode(new
TheTree.InsertNode(new
Node(10));
Node(11));
Node(5));
Node(1));
Node(20));
Node(7));
Node(15));
TheTree.OutputTree();
}
VB.NET
Sub Main(args As String())
Dim TheTree As TreeClass = New TreeClass()
TheTree.InsertNode(New Node(10))
TheTree.InsertNode(New Node(11))
TheTree.InsertNode(New Node(5))
TheTree.InsertNode(New Node(1))
TheTree.InsertNode(New Node(20))
TheTree.InsertNode(New Node(7))
TheTree.InsertNode(New Node(15))
TheTree.OutputTree()
End Sub
© Cambridge University Press & Assessment 2024
Page 35 of 50
May/June 2024
www.dynamicpapers.com
Marks
4
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
2(c)(ii)
Answer
May/June 2024
www.dynamicpapers.com
Marks
Python
TheTree = TreeClass()
TheTree.InsertNode(Node(10))
TheTree.InsertNode(Node(11))
TheTree.InsertNode(Node(5))
TheTree.InsertNode(Node(1))
TheTree.InsertNode(Node(20))
TheTree.InsertNode(Node(7))
TheTree.InsertNode(Node(15))
TheTree.OutputTree()
2(c)(iii)
1 mark for correct output e.g.
© Cambridge University Press & Assessment 2024
1
Page 36 of 50
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
3(a)
May/June 2024
www.dynamicpapers.com
Answer
1 mark each
NumberArray declared (in main) with the 7 correct values in order (integer) 100 85 644 22 15 8 1
e.g.
Java
public static void main(String args[]){
Integer[] NumberArray = new Integer[7];
NumberArray[0] = 100;
NumberArray[1] = 85;
NumberArray[2] = 644;
NumberArray[3] = 22;
NumberArray[4] = 15;
NumberArray[5] = 8;
NumberArray[6] = 1;
}
VB.NET
Sub Main(args As String())
Dim NumberArray(7) As Integer
NumberArray(0) = 100
NumberArray(1) = 85
NumberArray(2) = 644
NumberArray(3) = 22
NumberArray(4) = 15
NumberArray(5) = 8
NumberArray(6) = 1
EndSub
Python
NumberArray = [100, 85, 644, 22, 15, 8, 1]
© Cambridge University Press & Assessment 2024
Page 37 of 50
Marks
1
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
3(b)(i)
May/June 2024
www.dynamicpapers.com
Answer
1 mark each
Recursive function written with recursive call
Correct base case and return
Correct while loop control and internal
All correct and structure followed
4
e.g.
Java
public static Integer[] RecursiveInsertion(Integer[] IntegerArray, Integer NumberElements){
Integer LastItem;
Integer CheckItem;
if(NumberElements <= 1){
return IntegerArray;
}else{
RecursiveInsertion(IntegerArray, NumberElements - 1);
LastItem = IntegerArray[NumberElements - 1];
CheckItem = NumberElements - 2;
}
Boolean LoopAgain = true;
if(CheckItem < 0){
LoopAgain = false;
}else if(IntegerArray[CheckItem] < LastItem){
LoopAgain = false;
}
while(LoopAgain){
IntegerArray[CheckItem + 1] = IntegerArray[CheckItem];
CheckItem = CheckItem - 1;
if(CheckItem < 0){
LoopAgain = false;
© Cambridge University Press & Assessment 2024
Marks
Page 38 of 50
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
Answer
}else if(IntegerArray[CheckItem] <= LastItem){
LoopAgain = false;
}
3(b)(i)
}
}
IntegerArray[CheckItem + 1] = LastItem;
return IntegerArray;
VB.NET
Function RecursiveInsertion(IntegerArray, NumberElements)
Dim LastItem, CheckItem As Integer
If NumberElements <= 1 Then
Return IntegerArray
Else
RecursiveInsertion(IntegerArray, NumberElements - 1)
LastItem = IntegerArray(NumberElements - 1)
CheckItem = NumberElements - 2
End If
Dim LoopAgain As Boolean = True
If CheckItem < 0 Then
LoopAgain = False
ElseIf IntegerArray(CheckItem) <= LastItem Then
LoopAgain = False
End If
While LoopAgain
IntegerArray(CheckItem + 1) = IntegerArray(CheckItem)
CheckItem = CheckItem - 1
If CheckItem < 0 Then
LoopAgain = False
ElseIf IntegerArray(CheckItem) <= LastItem Then
© Cambridge University Press & Assessment 2024
Page 39 of 50
May/June 2024
www.dynamicpapers.com
Marks
9618/42
Cambridge International AS & A Level – Mark Scheme
PUBLISHED
Question
3(b)(i)
Answer
LoopAgain = False
End If
End While
IntegerArray(CheckItem + 1) = LastItem
Return IntegerArray
End Function
Python
def RecursiveInsertion(IntegerArray, NumberElements):
if NumberElements <= 1:
return IntegerArray
RecursiveInsertion(IntegerArray,NumberElements - 1)
LastItem = IntegerArray[NumberElements - 1]
CheckItem = NumberElements - 2
LoopAgain = True
if CheckItem < 0:
LoopAgain = False
elif IntegerArray[CheckItem] <= LastItem:
LoopAgain = False
while (LoopAgain):
IntegerArray[CheckItem + 1] = IntegerArray[CheckItem]
CheckItem = CheckItem - 1
if CheckItem < 0:
LoopAgain = False
elif IntegerArray[CheckItem] <= LastItem:
LoopAgain = False
IntegerArray[CheckItem + 1] = LastItem return IntegerArray
© Cambridge University Press & Assessment 2024
Page 40 of 50
May/June 2024
www.dynamicpapers.com
Marks