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

Question 3(d) 2025 · May-June · Paper 41 · 5 marks

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

Official answer for Question 3

Part (d)

Question 1

mark each

Question 5

  • Procedure header (and end) taking node as parameter, that is recursive
  • Checking if left is null and recursive call if not null
  • Outputting node's data
  • Checking if right is null and recursive call if not null
  • Correct order
✓
9618/41
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2025
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
Example program code:
✓
Python
✓
def OutputInOrder(RootNode):
✓
if RootNode.GetLeft() != None:
✓
OutputInOrder(RootNode.GetLeft())
✓
print(RootNode.GetData())
✓
if RootNode.GetRight() != None:
✓
OutputInOrder(RootNode.GetRight())
✓
VB.NET
✓
Sub OutputInOrder(RootNode)
✓
If RootNode.GetLeft() IsNot Nothing Then
✓
OutputInOrder(RootNode.GetLeft())
✓
End If
✓
Console.WriteLine(RootNode.GetData())
✓
If RootNode.GetRight() IsNot Nothing Then
✓
OutputInOrder(RootNode.GetRight())
✓
End If
✓
End Sub
✓
Java
✓
public static void OutputInOrder(Node RootNode){
✓
if(RootNode.GetLeft() != null){
✓
OutputInOrder(RootNode.GetLeft());
✓
}
✓
System.out.println(RootNode.GetData());
✓
if(RootNode.GetRight() != null){
✓
OutputInOrder(RootNode.GetRight());
✓
}
✓
}

Mark scheme 9618_s25_ms_41.pdf →

Show text version of question

Question 3

Part (d)

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

Part (d)

The recursive procedure OutputInOrder() outputs the data stored in the binary tree in

ascending numerical order.

The procedure takes a Node object as a parameter and then:

  • checks if the left node is null. If there is a left node, the function calls itself with the left
  • node

  • outputs the data of the current node
  • checks if the right node is null. If there is a right node, the function calls itself with the

right node.

Write program code for OutputInOrder()

Save your program.

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

[5]
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