GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 exactly 2?
- A. 40/120
- B. 48/120
- C. 32/120
- D. 64/120
Correct answer: A. 40/120
Count the orders by resulting height: heights 2, 3, 4 occur 40, 64, 16 times respectively (total 120). Height 2 needs a shape with every key within two levels of the root, e.g. a perfect-looking tree with 5 nodes.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- 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…
- A max-heap is built from [50, 30, 40, 10, 20, 35, 25, 5, 8, 15, 12] by bottom-up heapify. Two delete-max operations are then performed…