Completed first binary search algorithm