Skip to content

Conversation

mabrod
Copy link

@mabrod mabrod commented Feb 17, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant