Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q6 — Binary Search Trees

Explain with AI

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

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

Choose one option
View worked solution

Answer: B

To find the minimum and maximum possible heights of a Binary Search Tree (BST) with n=15n = 15 nodes, we use the definition that the height of a single-node tree is 00.

1. Maximum Height

The maximum height occurs when the tree is completely skewed (either left-skewed or right-skewed), where each level contains exactly one node.

For a skewed tree with nn nodes, the height is given by:

hmax=n−1h_{\text{max}} = n - 1

Substituting n=15n = 15:

hmax=15−1=14h_{\text{max}} = 15 - 1 = 14

2. Minimum Height

The minimum height occurs when the tree is as balanced as possible (a perfect binary tree).

For a binary tree of height hh, the maximum number of nodes it can accommodate is:

Nmax=2h+1−1N_{\text{max}} = 2^{h+1} - 1

We need to find the minimum height hh such that the tree can accommodate 1515 nodes:

2h+1−1≥152^{h+1} - 1 \ge 15 2h+1≥162^{h+1} \ge 16 h+1≥4  ⟹  h≥3h+1 \ge 4 \implies h \ge 3

For h=3h = 3, the maximum number of nodes is 23+1−1=152^{3+1} - 1 = 15. Thus, a perfectly balanced binary tree of height 33 can accommodate exactly 1515 nodes.

Therefore, the minimum and maximum possible heights of TT are 3 and 14 respectively.

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

Published
Report a correction
Keep exploringMore Binary Search Trees questions