Data-Structures-and-Algorithms-in-Java icon indicating copy to clipboard operation
Data-Structures-and-Algorithms-in-Java copied to clipboard

make sure to add correct end boundary for input

Open mabrod opened this issue 1 year ago • 0 comments

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

mabrod avatar Feb 17 '23 02:02 mabrod