Question 6(b) 2018 · May-June · Paper 42 · 8 marks
Reveal official mark-scheme answer
Official answer for Question 6
Part (b)
Question 1
mark for outputting all the leaf data values
Question 8
Show text version of question
Question 6
Part (b)
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 (b)
A new command has been added to initialise the pointers of the binary tree to − 1 to indicate
they are not in use.
with a LeftPointer of − 1 and a RightPointer of − 1 is a leaf.
Write a recursive function, in program code, to traverse the binary tree and output the value of DataValue for each leaf node.
Programming language ............................................................................................................
Program code
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[8]
Question 23
Question 24
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
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 9608_s18_qp_42.pdf
