Algorithms and Data Structures · Junior · Question 32 of 75
What is the time complexity of binary search?
- ✓Correct answer: O(log n)
- 2O(1)
- 3O(n)
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.
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