Question 2(b)(iii) 2024 · May-June · Paper 42 · 4 marks
Reveal official mark-scheme answer
Official answer for Question 2
Part (b)
(iii)
Question 1
mark each
Question 4
Show text version of question
Question 2
Part (b)
(iii)
Question 2
A binary tree stores data in ascending order. For example:
Question 15
8 19
3 10
Object‑Oriented Programming (OOP).
The binary tree is stored as a 1D array of nodes. Each node contains a left pointer, a data value and a right pointer.
The class Node stores the data about a node.
Node LeftPointer : INTEGER stores the index of the node to the left in the binary tree
Data : INTEGER stores the node’s data
RightPointer : INTEGER stores the index of the node to the right in the binary tree Constructor() initialises Data to its parameter value initialises LeftPointer and RightPointer to −1
GetLeft() returns the left pointer
GetRight() returns the right pointer
GetData() returns the data value
SetLeft() assigns the parameter to the left pointer
SetRight() assigns the parameter to the right pointer
SetData() assigns the parameter to the data The class TreeClass stores the data about the binary tree.
TreeClass Tree[0:19] : Node an array of 20 elements of type Node
FirstNode : INTEGER stores the index of the first node in the tree
NumberNodes : INTEGER stores the quantity of nodes in the tree Constructor() initialises FirstNode to −1 and NumberNodes to 0 initialises each element in Tree to a Node object with the data value of −1
InsertNode() takes a Node object as a parameter, inserts it in the array and updates the pointer for its parent node
OutputTree() outputs the left pointer, data and right pointer of each node in Tree
Nodes cannot be deleted from this tree.
(iii)
The method OutputTree()outputs the left pointer, the data and the right pointer for
each node that has been inserted into the tree. The outputs are in the order they are saved in the array.
If there are no nodes in the array, the procedure outputs ‘No nodes’.
Write program code for OutputTree().
Save your program.
Copy and paste the program code into part 2(b)(iii) in the evidence document.
Question 9
Why this question appears here
71% assigned-topic match · Programming › Constructs
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_s24_qp_42.pdf
