In an interview I was offered the following:
public class Main {
public static void main(String[] args) {
int [] array = new int [10000];
for (int i = 0; i < array.length; i++) {
}
for (int x = array.length-1; x >= 0; x--) {
}
}
}
Is it the same as iterating an array either from the very end or from the very beginning? As far as I understand, this would be the same, since the complexity is constant ie O (1)? I'm right?
I was also asked about the complexity of ArrayList compared to other collections in java like LinkedList.
Thank.
source
share