completed binary search algorithm