Browsed by
Month: August 2018

Traversing an array without using length property

Traversing an array without using length property

We often face an interview question when it is asked to search or traverse an array without knowing/using the length property. In Java, if you try to access the element that is outside the length of the array it will give you an exception as java.lang.ArrayIndexOutOfBoundsException. Here I have one implementation of a binary search where I will not use the length property of the array. import static java.lang.Math.pow; public class BinarySearchWithoutLength { public static Integer binarySearch(final Integer[] elements, final Integer find) {…

Read More Read More