The binary lookup algorithm (also known as the binary lookup algorithm) is relatively efficient and is a search algorithm for finding a particular element in an ordered array.
Steps:
The first step is to find the middle element of the array, and if the middle element in the array equals the element to be found, the lookup ends;
Step two: If the element you are looking for is greater than or less than the middle element of the array, look in the half of the array that is greater than or less than the middle element, and step one also starts from the middle element;
Step three: If the array is empty, the representative cannot be found;
The binary lookup algorithm reduces the search scope by half, and the time complexity is: Log (n)
Here are two ways to implement the algorithm (Loop implementation and recursive implementation):
Binary search algorithm