is a commonly used algorithm to find a efficiently in a . It follows the approach, dividing the array into smaller subproblems. This technique can be implemented using either or recursion.
In binary search, the array is divided into two parts by finding the . The mid-point is the at the middle of the array. The target element is then compared with the element at the mid-point. If they are equal, the search is successful, and the index of the target element is returned. If the target element is smaller, the search continues on the left half of the array. Likewise, if the target element is larger, the search continues on the right half of the array.
Binary search has a of O(log n), where n is the size of the sorted array. This logarithmic time complexity arises from dividing the search space in half with each . Additionally, binary search has a of O(1), as it only needs a few variables to store the left and right boundaries as indices.
Keywords
index | space complexity | comparison | mid-point | sorted array | binary search | time complexity | divide and conquer | target element | iteration |