Big O complexity of simple for not always linear?

Posted by i30817 on Stack Overflow See other posts from Stack Overflow or by i30817
Published on 2010-03-16T01:26:57Z Indexed on 2010/03/16 1:29 UTC
Read the original article Hit count: 393

Filed under:
|
|

I'm sure most of you know that a nested loop has O(n^2) complexity if the function input size is n

for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
...
}
}

I think that this is similar, by a analogous argument, but i'm not sure can anyone confirm?

for(int i = 0, max = n*n; i < max; i++{
...
}

If so i guess that there is some kinds of code whose big O mapping is not immediately obvious besides recursion and subroutines.

© Stack Overflow or respective owner

Related posts about theory

Related posts about complexity