Past-paper question · 2025 May-June · Paper 41 · Q3(c)(iii)

Question 3(c)(iii) 2025 · May-June · Paper 41 · 6 marks

Original past-paper question for 3(C)(III)
Original past-paper question for 3(C)(III)
Original past-paper question for 3(C)(III)
Original past-paper question for 3(C)(III)
Reveal official mark-scheme answer Official mark-scheme answer for 3(C)(III)Official mark-scheme answer for 3(C)(III)Official mark-scheme answer for 3(C)(III)

Official answer for Question 3

Part (c)

(iii)

Question 1

mark each to max 6

Question 6

  • Insert method header (and end) taking 1 node parameter
  • If parameter < first node, checking if there is a left node …
  • … storing node in left node if it is null
  • If parameter >= first node, checking if there is a right node …
  • … storing node in right node if it is null
  • Looping until correct position is found // recursive calls
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example program code:
✓
Python
✓
def Insert(self, NewNode):
✓
CurrentNode = self. FirstNode
✓
Inserted = True
✓
while Inserted:
✓
if NewNode.GetData() < CurrentNode.GetData():
✓
if CurrentNode.GetLeft() == None:
✓
CurrentNode.SetLeft(NewNode)
✓
return True
✓
else:
✓
CurrentNode = CurrentNode.GetLeft()
✓
else:
✓
if CurrentNode.GetRight() == None:
✓
CurrentNode.SetRight(NewNode)
✓
return True
✓
else:
✓
CurrentNode = CurrentNode.GetRight()
✓
VB.NET
✓
Function Insert(NewNode)
✓
Dim CurrentNode As Node
✓
CurrentNode = FirstNode
✓
Dim Inserted As Boolean = True
✓
While Inserted
✓
If NewNode.GetData() < CurrentNode.GetData() Then
✓
If CurrentNode.GetLeft() Is Nothing Then
✓
CurrentNode.SetLeft(NewNode)
✓
Return True
✓
Else
✓
CurrentNode = CurrentNode.GetLeft()
✓
End If
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Else
✓
If CurrentNode.GetRight() Is Nothing Then
✓
CurrentNode.SetRight(NewNode)
✓
Return True
✓
Else
✓
CurrentNode = CurrentNode.GetRight()
✓
End If
✓
End If
✓
End While
✓
End Function
✓
Java
✓
public Boolean Insert(Node NewNode){
✓
Node CurrentNode = FirstNode;
✓
Boolean Inserted = true;
✓
while(Inserted){
✓
if(NewNode.GetData() < CurrentNode.GetData()){
✓
if(CurrentNode.GetLeft() == null){
✓
CurrentNode.SetLeft(NewNode);
✓
return true;
✓
}else{
✓
CurrentNode = CurrentNode.GetLeft();
✓
}
✓
}else{
✓
if(CurrentNode.GetRight() == null){
✓
CurrentNode.SetRight(NewNode);
✓
return true;
✓
}else{
✓
CurrentNode = CurrentNode.GetRight();
✓
}
✓
}
✓
}
✓
return false;
✓
}
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_s25_ms_41.pdf →

Show text version of question

Question 3

Part (c)

(iii)

Question 3

A program stores data in a binary tree that is designed using Object‑Oriented Programming

(OOP).

The tree stores data in ascending numerical order, for example:

Question 30

20 45

1 21 33 63

The class Node stores data about the nodes.

Node NodeData : Integer stores the node’s integer data

LeftNode : Node stores the node that is stored to the left of the current node, or a null value if there is no node to the left

RightNode : Node stores the node that is stored to the right of the current node, or a null value if there is no node to the right Constructor() initialises NodeData to its parameter value; initialises LeftNode and RightNode to a null value

GetLeft() returns LeftNode

GetRight() returns RightNode

GetData() returns NodeData

SetLeft() takes an object of type Node as a parameter and stores it in LeftNode

SetRight() takes an object of type Node as a parameter and stores it in RightNode

Question 7

The class Tree stores the tree.

Tree FirstNode : Node stores the root node in the tree Constructor() initialises FirstNode to its parameter value

GetRootNode() returns the node stored in FirstNode

Insert() stores its parameter node in the correct position in the tree

(iii)

The method Insert() takes a node as a parameter and then searches the tree to find

the position to insert the new node by:

  • checking whether the node’s data is less than or greater than the root node’s data
  • moving to the left node if the data is less than the root node’s data
  • moving to the right node if the data is greater than or equal to the root node’s data
  • repeating until the final position of the node is found and stores the node in that

position.

Write program code for Insert()

Save your program.

Copy and paste the program code into part 3(c)(iii) in the evidence document.

[6]

Question 9

Topic relevance

Why this question appears here

98% assigned-topic match · Computational thinking and problem-solving › Recursion

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9618_s25_qp_41.pdf

Keep practising this topic