Binary search is a searching algorithm that assumes we have a pre-sorted linear data structure. The premise is simple: we look at the middle element in the structure, and if the element we’re looking at is greater than the middle we look at the top sub-array, and if it’s less, we look at the bottom sub-array.
Say our value is to the left sub-array, then we set our high index as middle - 1. For the opposite case, we set our low index as middle + 1.
Because our search array is divided in half each iteration, we have n/2x=1, i.e., our time complexity is O(logn).