Skip to main content

GATE CSE 2017Data Structures › Trees & Binary Search TreesVerified

GATE CSE 2017 PYQ: Let T T T be a binary search tree with 15 15 15 nodes. The minimum and maximum possible heights of T T T…

Let TT be a binary search tree with 15 nodes. The minimum and maximum possible heights of TT are:

Note: The height of a tree with a single node is 0.

  1. A
    4 and 15 respectively.
  2. B
    3 and 14 respectively.
    Correct answer
  3. C
    4 and 14 respectively.
  4. D
    3 and 15 respectively.

Answer

(B) 3 3 3 and 14 14 14 respectively.

Approach

The height of a BST depends only on its shape, not on the ordering property (any binary-tree shape can be realized as a BST by assigning keys in the correct order). So the question reduces to: over all binary trees with $n = 15$ nodes, what are the largest and smallest possible heights, where height is counted in edges (single node $\Rightarrow h = 0$)? The tallest shape is the fully skewed chain; the shortest shape is the balanced/complete tree.

For $n = 15$ nodes with height measured in edges, the shortest BST is complete and needs $\lceil \log_2(n+1) \rceil - 1 = 3$ levels of edges, while the tallest is a skewed chain of height $n - 1 = 14$. Therefore the minimum and maximum heights are 3 and 14, i.e. option B.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.