Algorithms and Data Structures · Junior · Question 32 of 75

What is the time complexity of binary search?

Explanation

Each step halves the remaining range, so after about log₂ n steps only one element is left. For a billion elements that's about 30 comparisons.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 32

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