Binary Search is a highly efficient algorithm for finding an element in a sorted array. It works by repeatedly dividing the search interval in half. If the value of the target element is less than the middle element of the array, the search continues in the left half, otherwise, it continues in the right half. This process continues until the element is found or the interval is empty.
Time Complexity: O(log n)
Space Complexity: O(1) (iterative version) or O(log n) (recursive version)
Binary Search is a highly efficient algorithm for finding an element in a sorted array. It works by repeatedly dividing the search interval in half. If the value of the target element is less than the middle element of the array, the search continues in the left half, otherwise, it continues in the right half. This process continues until the element is found or the interval is empty.
Time Complexity: O(log n) Space Complexity: O(1) (iterative version) or O(log n) (recursive version)