What would be the time complexity for this snippet? I'm having a little trouble understanding how to find the time complexity of nested for loops with different conditions.
I originally thought that it would be n^3 x n^2 which gives O(n^5), but should it be (n^3)^2 which gives O(n^6)?
for(int i = 0; i < n*n; i++) { for(int j = 0; j < n*n*n; j++) { A(); //O(1) } }
n*n*n*O(1). With the outer loop, you haven*ntimes the complexity of the loop body, i.e. the complexity of the inner loop:(n*n)*(n*n*n*O(1)). So your initial thought was correct.i++in the inner loop, the complexity is O(n^2), presuming something else will terminate the inner loop. Else, if nothing terminates the inner loop it is O(∞).