Past-paper question · 2018 May-June · Paper 42 · Q6(b)

Question 6(b) 2018 · May-June · Paper 42 · 8 marks

Original past-paper question for 6(B)
Original past-paper question for 6(B)
Original past-paper question for 6(B)
Original past-paper question for 6(B)
Reveal official mark-scheme answer Official mark-scheme answer for 6(B)

Official answer for Question 6

Part (b)

Question 1

mark for outputting all the leaf data values

Question 8

✓
•
✓
Outputting BinaryTree[CurrentNode].DataValue only when both LeftPointer and RightPointer are -1
✓
1 mark per bullet to max 7
✓
•
✓
Function declaration
✓
•
✓
«taking CurrentNode or equivalent as parameter
✓
•
✓
Check if BinaryTree[CurrentNode].LeftPointer is not -1 «
✓
•
✓
« recursive call «
✓
•
✓
«with left pointer value as parameter
✓
•
✓
Check if BinaryTree[CurrentNode].RightPointer is not -1«
✓
•
✓
« recursive call«
✓
•
✓
« with right pointer value as parameter
✓
Python example code:
✓
def FindLeaves(CurrentNode):
✓
global BinaryTree
✓
if(BinaryTree[CurrentNode].LeftPointer != -1):
✓
FindLeaves(BinaryTree[CurrentNode].LeftPointer)
✓
if(BinaryTree[CurrentNode].RightPointer != -1):
✓
FindLeaves(BinaryTree[CurrentNode].RightPointer)
✓
if((BinaryTree[CurrentNode].RightPointer == -1) and
✓
(BinaryTree[CurrentNode].LeftPointer == -1)):
✓
print BinaryTree[CurrentNode].DataValue
✓
return
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s18_ms_42.pdf →

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.

A
record type, Node, is declared using pseudocode.

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

A
variable, NextNode, points to the next free 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.

A
leaf is a node of the binary tree which has no children. In the case of this binary tree, a node

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.

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 9608_s18_qp_42.pdf

Keep practising this topic