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.

```
using System;
namespace Algorithms.Searches
{
/// <summary>
/// TODO.
/// </summary>
/// <typeparam name="T">TODO. 2.</typeparam>
public class BinarySearcher<T> where T : IComparable<T>
{
/// <summary>
/// Finds index of item in array that equals to item searched for,
/// time complexity: O(log(n)),
/// space complexity: O(1),
/// where n - array size.
/// </summary>
/// <param name="sortedData">Sorted array to search in.</param>
/// <param name="item">Item to search for.</param>
/// <returns>Index of item that equals to item searched for or -1 if none found.</returns>
public int FindIndex(T[] sortedData, T item)
{
var leftIndex = 0;
var rightIndex = sortedData.Length - 1;
while (leftIndex <= rightIndex)
{
var middleIndex = leftIndex + (rightIndex - leftIndex) / 2;
if (item.CompareTo(sortedData[middleIndex]) > 0)
{
leftIndex = middleIndex + 1;
continue;
}
if (item.CompareTo(sortedData[middleIndex]) < 0)
{
rightIndex = middleIndex - 1;
continue;
}
return middleIndex;
}
return -1;
}
}
}
```