Algorithm
Binary Search Algorithm:
- Start with a sorted array and a target element to search for.
- Initialize two pointers, one at the beginning of the array and one at the end.
- Repeat the following steps until the pointers meet:
- Find the middle element of the current array segment.
- Compare the middle element with the target element.
- If they match, return the index of the middle element.
- If the target element is smaller than the middle element, move the end pointer to the middle - 1.
- If the target element is larger than the middle element, move the start pointer to the middle + 1.
- If the pointers meet without finding the target element, return "Not Found."
Example:

Fig. 1: Step-by-Step Process of Binary Search
Note: Binary Search is efficient but requires the input array to be sorted.