Question 2(d)(ii) 2017 · May-June · Paper 42 · 8 marks
Reveal official mark-scheme answer

Official answer for Question 2
Part (d)
(ii)
Question 8
- 1
Question 1
Question 1
Question 1
- 1
Question 1
Question 1
Question 1
Question 1
Question 1
Show text version of question
Question 2
Part (d)
(ii)
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.
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
- Direction, whose value is the direction of the
where the new node is to be added
pointer (“Left” or “Right”).
Question 7
(ii)
Complete the pseudocode to add a data item to the tree.
PROCEDURE AddToTree(BYVALUE NewDataItem : STRING)
// if no free node report an error
IF FreePointer ...............................................................................................................
THEN
OUTPUT("No free space left")
ELSE // add new data item to first node in the free list
NewNodePointer ← FreePointer
.................................................................................................................................
// adjust free pointer
FreePointer ← .................................................................................................
// clear left pointer
Tree[NewNodePointer].LeftPointer ← ......................................................
// is tree currently empty ?
IF ...........................................................................................................................
THEN // make new node the root node
....................................................................................................................
ELSE // find position where new node is to be added
Index ← RootPointer
CALL FindInsertionPoint(NewDataItem, Index, Direction)
IF Direction = "Left"
THEN // add new node on left
.......................................................................................................
ELSE // add new node on right
.......................................................................................................
ENDIF
ENDIF
ENDIF
ENDPROCEDURE
Question 9
Why this question appears here
72% 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_s17_qp_42.pdf
