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

Question 2(d)(ii) 2017 · May-June · Paper 42 · 8 marks

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

Official answer for Question 2

Part (d)

(ii)

✓
PROCEDURE AddToTree(ByVal NewDataItem : STRING)

Question 8

✓
// if no free node report an error
  • 1
✓
IF FreePointer =

Question 1

✓
THEN
✓
ERROR("No free space left")
✓
ELSE
✓
// add new data item to first node in the free list
✓
NewNodePointer ← FreePointer
✓
Tree[NewNodePointer].Data
✓
NewDataItem
✓
←

Question 1

✓
// adjust free pointer
✓
Tree[FreePointer].LeftPointer
✓
FreePointer ←

Question 1

✓
// clear left pointer
  • 1
✓
Tree[NewNodePointer].LeftPointer ←

Question 1

✓
// is tree currently empty ?
✓
RootPointer = -1
✓
IF

Question 1

✓
THEN
✓
// make new node the root node
✓
RootPointer
✓
NewNodePointer
✓
←

Question 1

✓
ELSE
✓
// find position where new node is to be added
✓
Index ← RootPointer
✓
CALL FindInsertionPoint(NewDataItem, Index, Direction)
✓
9608/42
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks
✓
IF Direction = "Left"
✓
THEN
✓
// add new node on left
✓
Tree[Index].LeftPointer
✓
NewNodePointer
✓
←

Question 1

✓
ELSE
✓
// add new node on right
✓
Tree[Index].RightPointer
✓
NewNodePointer
✓
←

Question 1

✓
ENDIF
✓
ENDIF
✓
ENDIF
✓
ENDPROCEDURE

Mark scheme 9608_s17_ms_42.pdf →

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.

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

(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

[8]

Question 9

Topic relevance

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

Keep practising this topic