add recursive version for binary search