Data-Structures-and-Algorithms-in-Java
Data-Structures-and-Algorithms-in-Java copied to clipboard
make sure to add correct end boundary for input
binary search recursive implementation does not handle correctly scenario when an element to search for is greater than the last input element by throwing the following exception: java.lang.ArrayIndexOutOfBoundsException: 10 at com.packt.datastructuresandalg.lesson2.sorting.BinarySearchRecursive.binarySearch(BinarySearchRecursive.java:12)
to fix it you need to make sure that in recursive binary search helper method you pass index of last element by subtracting 1 from the length of the input, not the length of the input