Big O help

Would the big oh notation of the Algorithm of:

for ( j = 0; j < n; j++ )

{

for ( k = j; k < n; k++ )

{

<some operation>

}

}

be : O(N^2) because there are 2 for loops increasing the count?
thanks for your help.
well, with my limited knowledge of big o i think i can answer this: it is O(n2) because the inner loop is O(n), and each iteration of the outer loop is O(n), so thats O(n * n) which is O(n2)
It is actually O(n2)·O(<some operation>).
It depends on cost of some operation too. In case where it is O(1), total cost will be O(n2)
In order to understand complexity better, I suggest to read through this:

http://stackoverflow.com/questions/487258/plain-english-explanation-of-big-o

There are many other sites which explain O-notation on a very intuitive level.
It's a bit more complicated (due to k=j) : O(n2 - ((n2 - n) / 2)).

Tip: replace <some operation> with (e.g.) ++sum and you'll find out whether your formular is correct.

[EDIT]
Simplifyed: O((n2 + n) / 2)
Last edited on
Topic archived. No new replies allowed.