The GATE Grind

GATE 2011 CS (CS1) – Question 39

Programming and Data Structures · Trees and Binary Search Trees · 2 marks · Multiple choice

An unlabelled binary-tree shape has n nodes and n distinct keys are supplied. In how many ways can the keys populate it to make a BST?

  1. 0
  2. 1
  3. $n!$
  4. $\frac1{n+1}\binom{2n}{n}$

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 1

Explanation

Every BST has keys in increasing order under inorder traversal. The fixed shape has one fixed sequence of inorder positions, so assigning the sorted keys to those positions uniquely determines every label. Exactly one assignment works, B. Catalan counts apply when the shape itself can vary.

More Trees and Binary Search Trees questions

All Trees and Binary Search Trees questions →