GATE Computer ScienceModerateGATE CS (PYQ pattern)

Binary search on a sorted array of 20 distinct keys uses mid = ⌊(lo + hi)/2⌋ and one three-way comparison per probe, stopping when lo > hi. For an absent key, each of the 21 gaps (before the first key, between consecutive keys, after the last) is equally likely. What is the average number of probes in an unsuccessful search?

  1. A. 3.70
  2. B. 5.00
  3. C. 4.48
  4. D. 4.33

Correct answer: C. 4.48

The search tree of 20 keys has levels 1–4 full (15 nodes) and 5 nodes on level 5, so 21 external gaps: the 10 below level-5 nodes cost 5 probes, the other 11 cost 4. Average = (10·5 + 11·4)/21 = 94/21 ≈ 4.48. 3.70 is the successful-search average; 5.00 assumes every failure reaches the bottom level.

More Algorithms questions

Exams that ask this topic