Exploring a possible solution
Now that we understand the limitations of linear search on a sorted dataset, a more intelligent approach is needed. Checking each item individually becomes inefficient as the collection grows. Let’s explore how a more efficient search method, called binary search, solves this problem at scale.
Binary search
Binary search is one of computer science's most widely used search algorithms and is used to find the position of a target value in a sorted array by leveraging the array's sorted order. Instead of a linear search, it uses an intelligent strategy by partitioning the search space into two halves and discarding the half where the target cannot be present.
Looking at the problem of finding a student who scored 85 marks in a sorted list of results containing thousands of students. Instead of checking each student's score individually, you begin by examining the score of the student at the middle of the list.
Liking the course? Check our discounted plans to continue learning.