I'm feeling very very stupid because I've solved much harder stuff than this. This is supposed to be an implementation of ordered binary search. Whenever I trace the 12, a stackoverflow error pops up. Any help please?
public class binarySearch {
public static void main(String[] args) {
int[] arr = { 1, 5, 6, 8, 12, 88 };
System.out.println(binaryHelper(0, arr.length - 1, 12, arr));
}
public static int binaryHelper(int first, int last, int target, int[] arr) {
if(first > last) return -1;
else {
int mid = first + last / 2;
if(arr[mid] == target) return mid;
else if(arr[mid] > target) return binaryHelper(first, mid - 1, target, arr);
else return binaryHelper(mid + 1, last, target, arr);
}
}
}