Worst-Case Binary Search Comparisons

Coding
Search
Easy
A sorted array contains 1000 distinct values. Using binary search, what is the maximum number of midpoint comparisons needed to determine whether a target value is present?
Hint 1

Each comparison in binary search halves the size of the remaining candidate range.

Hint 2

Find the smallest integer with .

Show worked solution
  1. 1. Relate comparisons to halving the search space

    Binary search needs comparisons in the worst case to narrow candidates down to one.

Answer: 10

Related roles: Browse quant jobs

Related problems