Past-paper question · 2022 October-November · Paper 43 · Q3(d)

Question 3(d) 2022 · October-November · Paper 43 · 7 marks

Question 3

Part (d)

Question 3

A binary tree consists of nodes. Each node has 3 integer values: a left pointer, data and a right

pointer.

The binary tree is stored using a global 2D array.

The pseudocode declaration for the array is:

DECLARE ArrayNodes : ARRAY[0:19, 0:2] OF INTEGER

For example:

  • ArrayNodes[0, 0] stores the left pointer for the first node.
  • ArrayNodes[0, 1] stores the data for the first node.
  • ArrayNodes[0, 2] stores the right pointer for the first node.
  • 1 indicates a null pointer, or null data.

Part (d)

A post order traversal performs the following operation:

  • visit the left node
  • visit the right node
  • output the root.

For example, in the following tree, the output would be: 3 9 25 60 50

Question 50

25 60 3 9 An outline of the PostOrder() procedure is:

  • If left node is not empty, make a recursive call with the left node as the root.
  • If right node is not empty, make a recursive call with the right node as the root.
  • Output the current root node.

The procedure PostOrder() takes the root node as a parameter.

Write program code for the procedure PostOrder().

Save your program.

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

[7]

Question 11

Reveal official mark-scheme answer Official mark-scheme answer for 3(D)

Official answer for Question 3

Part (d)

Question 1

mark per point (Max 7):

Question 7

✓
•
✓
(procedure) header (and end where appropriate) with one parameter
✓
(root node or index of root node) and at least one recursive call
✓
•
✓
checking if left node is −1 …
✓
•
✓
… if not recursive call with parameter as ArrayNodes[RootNode[0]]
✓
•
✓
checking if right node is −1 …
✓
•
✓
…if not recursive call with parameter as ArrayNodes[RootNode[2]]
✓
•
✓
outputting the element at the parameter RootNode[]
✓
•
✓
all 3 in the correct order
✓
Example program code:
✓
Python
✓
def PostOrder(RootNode):
✓
if RootNode[0] != -1:
✓
PostOrder(ArrayNodes[RootNode[0]])
✓
if RootNode[2] != -1:
✓
PostOrder(ArrayNodes[RootNode[2]])
✓
print(str(RootNode[1]))
✓
Java
✓
public static void PostOrder(Integer[] RootNode){
✓
if(RootNode[0] != -1){
✓
PostOrder(ArrayNodes[RootNode[0]]);
✓
}
✓
if(RootNode[2] != -1){
✓
PostOrder(ArrayNodes[RootNode[2]]);
✓
}
✓
System.out.println(RootNode[1]);
✓
}
✓
VB.NET
✓
Sub PostOrder(RootNode() As Integer)
✓
Dim TempArray(2) As Integer
✓
If RootNode(0) <> -1 Then
✓
TempArray(0) = ArrayNodes(RootNode(0),
✓
0)
✓
TempArray(1) = ArrayNodes(RootNode(0),
✓
1)
✓
TempArray(2) = ArrayNodes(RootNode(0),
✓
2)
✓
PostOrder(TempArray)
✓
End If
✓
If RootNode(2) <> -1 Then
✓
TempArray(0) = ArrayNodes(RootNode(2),
✓
0)
✓
TempArray(1) = ArrayNodes(RootNode(2),
✓
1)
✓
TempArray(2) = ArrayNodes(RootNode(2),
✓
2)
✓
PostOrder(TempArray)
✓
End If
✓
Console.WriteLine(RootNode(1))
✓
End Sub
✓
Cambridge International AS & A Level – Mark Scheme
✓
9618/43
✓
October/November
✓
PUBLISHED
✓
2022
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_w22_ms_43.pdf →

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_w22_qp_43.pdf

Keep practising this topic