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?

  1. A. 40/120
  2. B. 48/120
  3. C. 32/120
  4. 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.

More Programming and Data Structures (GATE) questions

Exams that ask this topic