GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Among all 429 structurally different binary search trees on the keys 1 to 7, in how many is key 3 a leaf?
- A. 143
- B. 132
- C. 66
- D. 90
Correct answer: B. 132
Two keys adjacent in sorted order are always in an ancestor-descendant relation in a BST (no key lies between them to split them apart). Key 3 is a leaf exactly when 2 and 4 are both its ancestors, and deleting that leaf is a bijection onto all BSTs on the six keys {1, 2, 4, 5, 6, 7}: in each of those, 2 and 4 are adjacent and hence related, and the empty slot between them is exactly where 3 must hang. So the count is C6 = 132 (a brute force over the 429 trees agrees).
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. An iterative preorder…
- Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. Its level-order traversal…
- Which one of the following sequences can NOT be the postorder traversal of a binary search tree with distinct keys?
- Keys 1 to 6 are inserted into an empty BST in each of the 720 possible orders. For how many orders is the height of the resulting tree…
- All 120 insertion orders of keys 1..5 into an empty BST are equally likely. What is the probability that the resulting tree has height…
- Keys 40, 20, 10, 25, 30, 22, 50, 5, 3, 35, 45, 60 are inserted in this order into an initially empty AVL tree (a double rotation counts as…