Question bank › A-level Computer Science › Fundamentals of data structures

Trees and binary trees

Answer on paper first, then reveal the mark scheme one mark at a time.

1Hard5 marks

A binary search tree is stored in an array of records. Each record has a Left pointer, a Data field and a Right pointer. A pointer value of −1 means there is no child. Items are inserted using alphabetical order: an item that comes before a node's data goes to the left of that node and an item that comes after it goes to the right. The items are inserted in the following order, with Mango as the root at index 0 and each later item stored at the next index:

Mango, Cherry, Peach, Apple, Fig, Plum, Banana, Kiwi

(a) Complete the Left and Right pointers in the table. [3]

IndexLeftDataRight
0Mango
1Cherry
2Peach
3Apple
4Fig
5Plum
6Banana
7Kiwi

(b) Describe how the tree would be searched to determine whether Grape is stored in it, stating the items compared. [2]

Stuck on this topic?

Book a free 30-minute session on WhatsApp and we'll find exactly which step is costing you the marks. Or build a timed paper on it.

Free 30-minute session