This method requires the array to be in order for the method to be applicable. As linear it does not need any requirements for it to be applicable.
This method is complex compared to linear search.
More efficient than a linear search as the only requirements is that the values which are in the array to be sorted in order. E.g. Instead of testing the array's first element, binary searching starts with the element in the middle. If the element happens to contain the desired value, the search is over.
Binary search can only work if the values are sorted in an order. Instead from going left to right and checking if it meets the conditions, binary search starts from the middle (the median) and determines if the select value is higher or lower than the target value, depending on whether the select value is higher or lower it eliminates the side and the select value in which the select value is, higher or lower than the target value. This process repeats until the target value is found.
Every time the search makes a comparison and fails to find the desired element, it eliminates half of the remaining portion of the array that must be searched.
From top to bottom, this is how binary search works.
This is an pseudocode example of how binary search could be used to search for an item in an array.
Advantage
More efficient alternative to linear search, for a lot of elements.
Every time the search makes a comparison and fails to find the desired element, it eliminates half of the remaining portion of the array that must be searched.
This example shows that Binary is a more efficient search algorithm compared to linear search. Binary search identified the targeted value in only 3 steps, where as Linear search identified the target value in 11 steps.
Disadvantage
Requires a sorted array.
This method is complex compared to linear search.
This example sorts the array before binary search is applicable to be used.