I always thought that the elementary operation from an algorithm was the operation located inside the most inner loop. I found very little detail about this in books and online articles, maybe because it was supposed to be something trivial, but the few that cared to explain what should be the elementary operation in an algorithm, they always says that its the operation that is executed the most, that is, the one located inside the most inner loop.
And as such, in this algorithm:
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
int N = in.nextInt();
if (N == 0)
break;
long cost = 0;
int[] houses = new int[N];
for (int i = 0; i < N; ++i)
houses[i] = in.nextInt();
for (int i = 0; i < N - 1; ++i) {
cost += Math.abs(houses[i]);
houses[i + 1] += houses[i];
}
System.out.println(cost);
}
}
}
I said that the elementary operation was the assignment operation houses[i] = in.nextInt();
inside the first for, because it runs N times while the second for runs N-1 times.
My teacher is saying that this is incorrect and that the elementary operation in this algorithm is the operation inside the second for.
By any chances, there has exceptions where the elementary operation isn't the operation located inside the most inner loop, or she is wrong?