Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

UGC-NET | UGC-NET CS 2017 Dec 2 | Question 22

  • Last Updated : 15 Mar, 2018

The following numbers are inserted into an empty binary search tree in the given order:

10, 1, 3, 5, 15, 12, 16

What is the height of the binary search tree ?
(A) 3
(B) 4
(C) 5
(D) 6


Answer: (A)

Explanation: We have 10, 1, 3, 5, 15, 12, 16 keys and we have to insert these keys into a binary search tree (BST):

  • Step-1. Insert 10 into the BST.
  • Step-2. Compare 1 with 10 it is less than 10 So it will be left child for 10.
  • Step-3. Now compare next key ie 3 to 10, it is less than 10,it will be in left sub tree of 10. Now compare 3 with next node ie 1, 3 is greater than 1 so it will be right child to node 1.
  • Step-4. Next key is 5 follow the same procedure as in previous step. 5 will be right child for node 3.
  • Step-5. Key 15 will be compared to parent node first and it is greater than 10 so it will be right child to node 10.
  • Step-6. Key 12 will be compared to parent node first it is greater so next comparison will be to the right child of parent node ie 15,now 12 is less than 15 so 12 will be left child node 15.
  • Step-7. Now the last key 16 will be compared to parent node first, it is greater than 10 so comparision will be shifted to right child of 10 ie 15 and key 16 is greater than 15 also so 16 will be right child to node 15.

      Here is the constructed BST:

      This tree has 4 level and height of tree is level – 1 So height of this tree will be 4-1 = 3.

      So, option (A) is correct.


      Quiz of this Question

      My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!