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

Question 6(a) 2018 · May-June · Paper 42 · 5 marks

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

Official answer for Question 6

Part (a)

Question 1

ma

✓
ark per bullet

Question 5

✓
•
✓
B
✓
Brown left and black
✓
b
✓
right from n
✓
node 2
✓
•
✓
Y
✓
Yellow left and Purple
✓
P
✓
right from
✓
m node 1
✓
•
✓
P
✓
Peach left come
✓
es from 3
✓
•
✓
W
✓
White left from 6 and Pink left fr rom 7
✓
•
✓
G
✓
Grey left from 9 and orange righ
✓
ht from 9
✓
© U CLES 2018
✓
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 (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.

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 (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)

[5]

Question 22

Topic relevance

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

Keep practising this topic