ArraysLesson 13Free preview
DSA Binary Search
This lesson is part of DSA · All levels
Summary
Binary search works on data that's sorted by continuously dividing the search range into two. Compare the middle element to the target, then throw out half the range that is unlikely to contain the target. Because of this, the search is done in O(log n), much faster than linear search for big data.
Key points
- Just for the data that's already sorted.
- Throw out half the rest of the range at each step
- Complexity
- It can be implemented iteratively or recursively
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.