How to calculate the time complexity of the following algorithm?
int x =0;
for (int i = 1; i < n; i++) {
for (int j = 1; j < n; ++j) {
x++;
n--;
}
}
I know that time complexity for nested for loops is equal to the number of times the innermost loop is executed.
like every nested loop that the outer loop is from 1 to n, it should run n times but here we have n-- that makes the algorithm run in better order. actually, I wrote this code in IDE and I printed the final result of x after loops end for different n value and I saw that nearly n times takes that we jump into inner for loop.
so I think that the whole order of this algorithm is O (n) but I am not sure
can someone help me prove it completely?