A binary search tree is generated by inserting in order the following integers:
The number of nodes in the left subtree and right subtree of the root respectively is
View worked solution
Answer: B
In a Binary Search Tree (BST), the first element inserted becomes the root node. For any subsequent element:
- If it is smaller than the root, it is placed in the left subtree.
- If it is larger than the root, it is placed in the right subtree.
The given insertion sequence is:
Here, the first element is , which becomes the root of the BST.
Now, we partition the remaining elements based on their relation to the root ():
-
Left Subtree: Elements less than
Total number of nodes in the left subtree =
-
Right Subtree: Elements greater than
Total number of nodes in the right subtree =
Thus, the number of nodes in the left and right subtrees of the root respectively is .
Free practice · Your answers on this page are not saved.
