GATE Computer ScienceEasyGATE CS (PYQ pattern)

A BST on 31 keys is perfectly balanced (all 5 levels full). Searching for each of the 31 keys with equal probability, what is the average number of key comparisons for a successful search (one comparison per node on the path, including the node holding the key)?

  1. A. 3.87 (120/31)
  2. B. 5.00
  3. C. 4.00
  4. D. 4.16 (129/31)

Correct answer: D. 4.16 (129/31)

Level d has 2^d nodes needing d + 1 comparisons: (1*1 + 2*2 + 4*3 + 8*4 + 16*5)/31 = 129/31, about 4.16.

More Programming and Data Structures (GATE) questions

Exams that ask this topic