The following numbers are inserted into an empty binary search tree in the given order: . What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?
View worked solution
Answer: B
We construct the Binary Search Tree (BST) by inserting the elements one by one according to the BST property (smaller elements to the left, larger elements to the right):
- 10 becomes the root.
- 1 is less than 10, so it goes to the left of 10.
- 3 is less than 10 but greater than 1, so it goes to the right of 1.
- 5 is less than 10, greater than 1, and greater than 3, so it goes to the right of 3.
- 15 is greater than 10, so it goes to the right of 10.
- 12 is greater than 10 but less than 15, so it goes to the left of 15.
- 16 is greater than 10 and greater than 15, so it goes to the right of 15.
The resulting tree structure is:
10
/ \\
1 15
\\ / \\
3 12 16
\\
5The height of the tree is the maximum number of edges from the root to any leaf node. The longest path is , which consists of edges. Thus, the height of the tree is .
Free practice · Your answers on this page are not saved.
