GateAI
Binary Search Trees

GATE CSE 2016 Set 2 · Q40

NAT2 marksMedium

Time

The number of ways in which the numbers 1, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 6, is _______ . *Note: The height of a tree with a single node is 0.*

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 64

Binary Search Trees

A binary search tree with 77 nodes has height 66 if and only if it is completely degenerate (a single linear chain of 77 nodes where every non-leaf node has exactly one child).

To construct such a tree by sequential insertion:

  1. For the first node (root), we must choose either the minimum or the maximum among the set of available numbers {1,2,3,4,5,6,7}\{1, 2, 3, 4, 5, 6, 7\}. If any intermediate number is chosen, it would force at least one element into its left subtree and at least one into its right subtree, preventing the tree from being a single chain of length 6. Thus, there are 2 choices (either 11 or 77).

  2. After choosing the root, 66 numbers remain. To maintain a single chain, the second node inserted must again be either the minimum or maximum of the remaining elements: 2 choices.

  3. Similarly, at each step kk for k=1,2,…,6k = 1, 2, \dots, 6, there are 22 choices (either the smallest or largest of the remaining elements).

  4. For the 7th node, only 11 element remains: 1 choice.

Total number of insertion sequences:

27−1=26=642^{7-1} = 2^6 = 64

Thus, the correct answer is 64.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Binary Search Trees previous year question is Q40 of the GATE CSE 2016 Set 2 paper. Find more GATE CSE PYQs on Binary Search Trees in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Search Trees PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Binary Search Trees in GATE CSE

Binary Search Trees has 21 GATE CSE PYQs across 17 papers from 2011 to 2026. 3 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2016 Set 2.

How GATE tests Binary Search Trees

More from GATE CSE 2016 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 2 · Q40 · NAT

The number of ways in which the numbers 1, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 6, is … *Note: The height of a tree with a single node is 0.*

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.