DSA-Bootcamp-Java
                                
                                 DSA-Bootcamp-Java copied to clipboard
                                
                                    DSA-Bootcamp-Java copied to clipboard
                            
                            
                            
                        ArrayIndexOutOfBoundsException in BinarySearch >> InfiniteArray
In this code of Infinite Array from BinarySearch lecture,
When we try to get target element more than half size of the array (like 100 or 130), it will throw ArrayIndexOutOfBoundsException like :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 13 out of bounds for length 11
	at Main.ans(InfiniteArray.java:17)
	at Main.main(InfiniteArray.java:8)
It is because when executing while(target > arr[end]), as end will be greater than size of the array, it will throw this error.
Or, Do we not consider this a bug as we are imagining an infinite array with no limit of the elements ?
I had the same doubt but apparently
 So yes, we do not consider this a bug as we are imagining an infinite array with no limit of the elements
So yes, we do not consider this a bug as we are imagining an infinite array with no limit of the elements
You can check PR #565
In this code of Infinite Array from BinarySearch lecture,
When we try to get target element more than half size of the array (like 100 or 130), it will throw ArrayIndexOutOfBoundsException like :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 13 out of bounds for length 11 at Main.ans(InfiniteArray.java:17) at Main.main(InfiniteArray.java:8)It is because when executing
while(target > arr[end]), as end will be greater than size of the array, it will throw this error.Or, Do we not consider this a bug as we are imagining an infinite array with no limit of the elements ?
Since this is an infinite array there is no chance of getting an exception like this, if you still get it, that means the array has a limit and it is not an infinite array :)