Question 6(a) 2018 · May-June · Paper 42 · 5 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (a)
Question 1
ma
Question 5
Show text version of question
Question 6
Part (a)
Question 6
An Abstract Data Type (ADT) is used to create an unordered binary tree. The binary tree is created
as an array of nodes. Each node consists of a data value and two pointers.
TYPE Node DECLARE DataValue : STRING DECLARE LeftPointer : INTEGER DECLARE RightPointer : INTEGER ENDTYPE
The following statement declares an array BinaryTree.
DECLARE BinaryTree : ARRAY[0:14] OF Node
The following diagram shows a possible node.
ArrayIndex DataValue LeftPointer RightPointer
0 "Red" 1 2
The commands in the following table create and add nodes to the binary tree.
Command Comment CreateTree(NodeData) Sets NextNode to 0. Writes NodeData into DataValue at the position NextNode Updates NextNode using NextNode = NextNode + 1 AttachLeft(NodeData, ParentNode) Writes NodeData into DataValue of NextNode Sets the LeftPointer of node ParentNode to NextNode Updates NextNode using NextNode = NextNode + 1 AttachRight(NodeData, ParentNode) Writes NodeData into DataValue of NextNode Sets the RightPointer of node ParentNode to NextNode Updates NextNode using NextNode = NextNode + 1
Question 21
Part (a)
The following commands are executed.
CreateTree("Red") AttachLeft("Blue", 0) AttachRight("Green", 0)
The following diagram shows the current state of the binary tree.
0 "Red" 1 2
1 "Blue" 2 "Green"
....... ....... ....... .......
....... ....... ....... .......
....... ....... ....... .......
Write on the diagram to show the state of the binary tree after the following commands have been executed.
AttachRight("Black", 2) AttachLeft("Brown", 2) AttachLeft("Peach", 3) AttachLeft("Yellow", 1) AttachRight("Purple", 1) AttachLeft("White", 6) AttachLeft("Pink", 7) AttachLeft("Grey", 9) AttachRight("Orange", 9)
Question 22
Why this question appears here
82% assigned-topic match · Data types and structures › Data types and records
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 9608_s18_qp_42.pdf
