Binary Search - Recursive Implementation
Explore the recursive implementation of binary search on sorted arrays. Learn how the algorithm successively halves the search space and analyze its running time using recurrence equations and recursion depth. Understand the nuances influencing the number of recursion steps and the overall time complexity in terms accessible to beginners.
We'll cover the following...
Binary search is a well-known search algorithm that works on an already-sorted input. The basic idea is to successively eliminate half of the remaining search space at each step till either the target is found or there's no more search space left.
Binary search is recursive in nature but can also be implemented iteratively. Below is the recursive implementation of binary search.
Binary Search Implementation
Recurrence Equation
The recurrence equation for binary search is given below:
...