Skip to content
Official PYQ · 2016

GATE CS 2016 Set 2 Q40 — Binary Search Trees

Explain with AI
The number of ways in which the numbers 1,2,3,4,5,6,71, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 66, is _________.

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

Answer: 64

A binary search tree (BST) with 77 nodes has a height of 66 if and only if it is a skewed binary tree (a chain where every internal node has exactly one child).

To construct such a tree through sequential insertions:

  1. The first inserted element (the root) must be either the minimum or the maximum of the 77 elements. This ensures all remaining elements go to one side (either entirely to the left or entirely to the right subtree). Thus, there are 22 choices.
  2. The second inserted element must be either the minimum or the maximum of the remaining 66 elements. This gives 22 choices.
  3. This pattern continues for each subsequent insertion. For the ii-th insertion (where 1≤i≤61 \le i \le 6), we have exactly 22 choices (the minimum or the maximum of the remaining elements).
  4. For the last (77-th) element, only 11 choice remains.

Therefore, the total number of valid insertion sequences is: 2×2×2×2×2×2×1=27−1=26=642 \times 2 \times 2 \times 2 \times 2 \times 2 \times 1 = 2^{7-1} = 2^6 = 64

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

Published
Report a correction
Keep exploringMore Binary Search Trees questions