binary search: optimization