Algorithm Analysis of Three nested loop
Three for loops gets you to n^3.

EDIT:

for (int i=0; i &lt; n; i++) // first n
..etc..
for (int j=0; j &lt; n; j++)  // second n
...etc...

Outer two are n, that makes n^2 so far. Next look at inner loop:

for (int k=0; k &lt;= j; k++) // third n

Innermost counts as another n for big O purposes even if running k to j instead of k to n. You're still on the order of n^3.

For that inner loop you're doing 1 + 2 + 3 ... loops as j iterates, so strictly speaking it's not exactly n^3 iterations, but n * n * (n+1)/2, but for big O purposes don't let that throw you off, it's n^3, the (n+1)/2 piece is just another layer of n. If n was 1,000,000 you'll end up with "on the order of" 10^18 loops.

Hope this helps.