GATE | GATE-CS-2017 (Set 1) | Question 17
Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are:
Note: The height of a tree with a single node is 0.
(A) 4 and 15 respectively
(B) 3 and 14 respectively
(C) 4 and 14 respectively
(D) 3 and 15 respectively
Answer: (B)
Explanation:
-
The minimum height of a binary search tree will be when tree is full complete tree:
Now, let h be the height of the binary tree, then, 2^{0}+2^{1}+2^{2}+2^{3}+…+2^{h}=2^{h+1}-1 <= n
So, Min height of a binary search tree = log2(n+1) – 1 = log2(15+1) – 1 = 4 – 1 = 3 -
The maximum height of a binary search tree will be when the tree is fully skewed: (like below)
Max height of the binary search tree = n-1 = 15 – 1 = 14, where the tree is Skewed tree
Therefore, option BÂ
Please Login to comment...