GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Seven keys have search probabilities (in percent, in sorted key order) 18, 6, 22, 14, 4, 20, 16 and only successful searches occur. The root has depth 1. The expected number of comparisons in an optimal binary search tree is:

  1. A. 2.46
  2. B. 1.22
  3. C. 2.22
  4. D. 2.31

Correct answer: C. 2.22

The DP cost[i][j] = Σp + min over roots of the two sub-costs gives 222 for percent probabilities, i.e. 2.22 comparisons. The perfectly balanced tree costs 2.46, and counting depth from the root as 0 would give 1.22.

More Algorithms questions

Exams that ask this topic