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

1996

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

 50, 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

  1. A.

    (4, 7)

  2. B.

    (7, 4)

  3. C.

    (8, 3)

  4. D.

    (3, 8)

Attempted by 53 students.

Show answer & explanation

Correct answer: B

To determine the number of nodes in the left and right subtrees, we first construct the Binary Search Tree (BST) by inserting elements sequentially. The root is 50. Any value less than 50 goes to the left, and any greater value goes to the right.

So you can simply count the number looking at the i/p. less than 50 are 7. more than 50 are 4.

50 (Root)
                   /    \
                 15      62
                /  \    /  \
               5   20  58  91
              / \     \   \
             3   8   37   60
                    /
                   24

Explore the full course: Gate Guidance By Sanchit Sir