GATE Computer ScienceVery hardGATE CS (PYQ pattern)
How many structurally different binary search trees can be built on the keys 1..7 such that the height is at most 3 (a single node has height 0)?
- A. 429
- B. 69
- C. 365
- D. 1
Correct answer: B. 69
Of the C7 = 429 shapes, those of height at most 3 satisfy f(n, h) = sum over l of f(l, h-1) f(n-1-l, h-1) with f(0, h) = 1; evaluating it for n = 7, h = 3 gives 69.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Among all 429 structurally different binary search trees on the keys 1 to 7, in how many is key 3 a leaf?
- 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…