Past-paper question · 2017 May-June · Paper 42 · Q2(d)(i)

Question 2(d)(i) 2017 · May-June · Paper 42 · 7 marks

Original past-paper question for 2(D)(I)
Original past-paper question for 2(D)(I)
Original past-paper question for 2(D)(I)
Original past-paper question for 2(D)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 2(D)(I)

Official answer for Question 2

Part (d)

(i)

✓
TYPE Node

Question 7

✓
LeftPointer : INTEGER
✓
RightPointer : INTEGER

Question 1

✓
Data : STRING
✓
ENDTYPE
✓
OF Node
✓
DECLARE Tree : ARRAY[0 : 9]

Question 1

✓
DECLARE FreePointer : INTEGER
✓
DECLARE RootPointer : INTEGER
✓
PROCEDURE CreateTree()
✓
DECLARE Index : INTEGER
✓
RootPointer ← -1

Question 1

✓
FreePointer ← 0

Question 1

✓
FOR Index ← 0 TO 9
✓
// link nodes
✓
Tree[Index].LeftPointer ← Index + 1

Question 1

✓
Tree[Index].RightPointer ← -1

Question 1

✓
ENDFOR
✓
Tree[9].LeftPointer ← -1

Question 1

✓
ENDPROCEDURE
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s17_ms_42.pdf →

Show text version of question

Question 2

Part (d)

(i)

Question 2

An ordered binary tree Abstract Data Type (ADT) has these associated operations:

  • create tree
  • add new item to tree
  • traverse tree

The binary tree ADT is to be implemented as a linked list of nodes.

Each node consists of data, a left pointer and a right pointer.

A
program is to be written to implement the tree ADT. The variables and procedures to be

used are listed below:

Identifier Data type Description Data structure to store node data and associated Node RECORD pointers. LeftPointer INTEGER Stores index of start of left subtree. RightPointer INTEGER Stores index of start of right subtree. Data STRING Data item stored in node. Tree ARRAY Array to store nodes. NewDataItem STRING Stores data to be added. FreePointer INTEGER Stores index of start of free list. RootPointer INTEGER Stores index of root node. NewNodePointer INTEGER Stores index of node to be added. Procedure initialises the root pointer and free pointer CreateTree() and links all nodes together into the free list. Procedure to add a new data item in the correct AddToTree() position in the binary tree. Procedure that finds the node where a new node is to be added. Procedure takes the parameter NewDataItem and returns two parameters: FindInsertionPoint()

  • Index, whose value is the index of the node
  • where the new node is to be added

  • Direction, whose value is the direction of the

pointer (“Left” or “Right”).

Question 7

(i)

Complete the pseudocode to create an empty tree.

TYPE Node

.....................................................................................................................................

.....................................................................................................................................

.....................................................................................................................................

ENDTYPE

DECLARE Tree : ARRAY[0 : 9] ................................................................................

DECLARE FreePointer : INTEGER

DECLARE RootPointer : INTEGER

PROCEDURE CreateTree()

DECLARE Index : INTEGER

.....................................................................................................................................

.....................................................................................................................................

FOR Index ← 0 TO 9 // link nodes

..............................................................................................................................

..............................................................................................................................

ENDFOR

.....................................................................................................................................

ENDPROCEDURE

[7]

Question 8

Topic relevance

Why this question appears here

71% assigned-topic match · Data types and structures › Arrays

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_s17_qp_42.pdf

Keep practising this topic