I'm having some trouble fully understanding Big-O notation and how nested loops impact the running time. I know time complexity of nested loops is equal to the number of times the innermost statement is executed but I just want to check my understanding.
1
count=1
for i=1 to N
for j=1 to N
for k=1 to N
count+=1
Since there are 2 nested loops, it would be O(N3), correct?
2
count=1
for i=1 to N^2
for j=1 to N
count+=1
The outer loop iterates N2 and inner loops runs N times which makes it O(N3), right?
3
count=1
for (i=0;i<N;++i)
for (j=0;j<i*i;++j)
for (k=0;k<j;++k)
++count
This would be O(N) right since N is only being called in the first for loop?