Could you please help me to clarify what is the complexity of the following piece of code where I traverse through the "unvisited" items in an array on each step?
final int[] arr = {...};
for (int i = 0, length = arr.length; i < length; i++) {
System.out.print(arr[i]);
for (int j = i + 1; j < length; j++) {
System.out.print(arr[j]);
}
}
I bet it's O(NlogN)
or O(N√N)
, where N
is arr.length
Am I right? Could you explain to me why?
I think it's O(NlogN)
or O(N√N)
because on each step the "unvisited" part is reduced so it's less than O(N^2)
but still greater than O(N)