implements iterative binary search