GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 exactly 4 (a single node has height 0)?
- A. 32
- B. 208
- C. 400
- D. 240
Correct answer: B. 208
Height 5 (a path) needs every inserted key to be the current minimum or maximum: 2^5 = 32 orders. Height 4 means the longest root-to-leaf path has 5 nodes with exactly one key off it; enumerating all 720 orders gives the distribution height 2: 80, 3: 400, 4: 208, 5: 32.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- Keys 1, 2, 3, ..., 20 are inserted in increasing order into an initially empty AVL tree. What is the key at the root, and how many…
- An AVL tree of height 6 (a single node has height 0) has the minimum possible number of nodes, and its keys are 1, 2, ..., n for that…
- The array [4, 10, 3, 5, 1, 8, 7, 2, 9, 6, 11, 12] is converted into a max-heap by Floyd's bottom-up build (sift-down from the last…
- The keys 20, 15, 30, 10, 5, 25, 3, 18, 1 are inserted one by one into an initially empty min-heap (array form, each insert sifts up). How…