I'm working on an exercise about Big O notations and I was wondering if there are any experts here who could help me determine the notation for the following code. so far, I am assuming that it is O(N^2). because a for loop is called in another loop. What do you guys think?
public static Double average(Integer[] values) {
Integer sum = 0;
for (int i = 0; i < values.length; i++) {
sum += values[i];
}
return sum / values.length;
}
public static IDeque < Integer > slidingAvg(
Stack < Integer > values, int width
) {
IDeque < Integer > window = new ArrayDeque < > (width);
IDeque < Double > averages = new ArrayDeque < > (values.size());
for (int i = 0; i < width; i++) {
window.pushFirst(0);
}
for (int value: values) {
window.pullLast();
window.pushFirst(value);
Integer[] roll = window.toArray(new Integer[0]);
Double average = average(roll);
averages.push(average);
}
return averages;
}