In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. In particular, fractional cascading speeds up binary searches for the same value in multiple arrays. In 1957, William Wesley Peterson published the first method for interpolation search. In 1946, John Mauchly made the first mention of binary search as part of the Moore School lecture, a seminal and foundational college course in computing. In 1962, Hermann Bottenbruch exhibited an ALGOL 60 implementation of binary search that put the comparison for equality at the end, increase the average number of iterations by one, but reduce to one the number of comparisons per iteration.

If the target value is less than the component, the search continues in the lower half of the array. If the target value is greater than the component, the search continues in the upper half of the array. This is the case for other search algorithms based on comparisons, as while they may work faster on some target values, the average performance over all components is worse than binary search. In terms of iterations, no search algorithm that works only by comparing components can show better average and worst-case performance than binary search.

```
#include <stdio.h>
// Recursive Function- It returns location of x assumiung array arr[l..r] is present, otherwise -1
int binarysearch(int arr[], int l, int r, int x)
{
if (r >= l)
{
int mid = l + (r - l)/2;
// If element is present at middle
if (arr[mid] == x) return mid;
// If element is smaller than middle
if (arr[mid] > x) return binarysearch(arr, l, mid-1, x);
// Else element is in right subarray
return binarysearch(arr, mid+1, r, x);
}
// When element is not present in array
return -1;
}
int main(void)
{
// give function an array to work with
int arr[] = {2, 3, 4, 10, 40};
// get size of array
int n = sizeof(arr)/ sizeof(arr[0]);
//set value to look for
int x = 10;
// set result to what is returned from binarysearch
int result = binarysearch(arr, 0, n-1, x);
// print out result
(result == -1) ? printf("Element is not in the array\n")
: printf("Element is present at index %d\n", result);
return 0;
}
```