Skip to content
Official PYQ · 1996

GATE CS 1996 Q2.14 — Binary Search Trees

Explain with AI

A binary search tree is generated by inserting in order the following integers:

50,15,62,5,20,58,91,3,8,37,60,2450, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24

The number of nodes in the left subtree and right subtree of the root respectively is

Choose one option
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:

{50,15,62,5,20,58,91,3,8,37,60,24}\{50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24\}

Here, the first element is 5050, which becomes the root of the BST.

Now, we partition the remaining elements based on their relation to the root (5050):

  1. Left Subtree: Elements less than 5050 {15,5,20,3,8,37,24}\{15, 5, 20, 3, 8, 37, 24\}

    Total number of nodes in the left subtree = 77

  2. Right Subtree: Elements greater than 5050 {62,58,91,60}\{62, 58, 91, 60\}

    Total number of nodes in the right subtree = 44

Thus, the number of nodes in the left and right subtrees of the root respectively is (7,4)(7, 4).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Search Trees questions