Use binary search instead of iterative search to achieve O(log n) running time.