Advantages:
- It is better than a linear search algorithm since its run time complexity is O(logN).
- At each iteration, the binary search algorithm eliminates half of the list and significantly reduces the search space.
- The binary search algorithm works even when the array is rotated by some position and finds the target element.
Disadvantages:
- The recursive method uses stack space.
- Binary search is error-prone. Some of the common errors are as follows:
- Off-by-one errors: While determining the boundary of the next interval, there might be overlapping errors.
- Handling of duplicate items: While returning the first item, it might be possible we return a subsequence similar item.
- Numerical underflows/overflows: In huge arrays when computing indices. There might be overflows
- Recursive vs non-recursive implementation, which should be considered while designing as recursive takes stack space.
- Caching is poor.