Algorithms and Data Structures · Junior · Question 33 of 75

Roughly how many comparisons does binary search need in a sorted array of 1,000,000 elements?

Explanation

2²⁰ is about a million, so halving the range 20 times leaves one element. Linear search would need up to a million comparisons.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 33

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz