ZIMSEC A Level Computer Science Answer Key
Answers to Question 1: Binary Trees
(a) A binary tree is a hierarchical data structure in which each node
has at most two children,
which are referred to as the left child and the right child.
(b) For the given binary tree:
15
/ \
10 20
/\ \
8 12 25
(i) Pre-order traversal (Root, Left, Right): 15, 10, 8, 12, 20, 25
(ii) In-order traversal (Left, Root, Right): 8, 10, 12, 15, 20, 25
(iii) Post-order traversal (Left, Right, Root): 8, 12, 10, 25, 20, 15
(c) Practical applications of binary trees:
1. **Searching and Sorting**: Binary search trees (BSTs) are used
for efficient searching,
insertion, and deletion operations.
2. **Hierarchical Data Representation**: Binary trees can represent
hierarchical structures
like file systems or organizational charts.
(d) Pseudocode for inserting a new node into a binary search tree:
function insertNode(root, value):
if root is NULL:
create a new node with value and return it
if value < root.value:
root.left = insertNode(root.left, value)
else:
root.right = insertNode(root.right, value)
return root