Katkat

Count binary search steps for specific keys

BitkernelSoftware Engineer · Online Assessment

Last updated

This question evaluates understanding of binary search mechanics, counting comparisons during a specific execution, and competency in algorithmic analysis and control-flow reasoning.

You have the sorted array:

[22, 34, 55, 77, 89, 93, 99, 102, 120, 140]

Using standard binary search with low and high indices and mid = floor((low + high) / 2), how many comparisons are required to find each of the following keys: 77, 34, and 99?

Provide the triple (comparisons for 77, comparisons for 34, comparisons for 99).

Options:

  • A. 3, 3, 3
  • B. 3, 3, 4
  • C. 3, 4, 3
  • D. 4, 2, 4