Asymptotic analysis of three nested loops

I want to calculate the complexity of theta of this nested loop:

for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { for (int k = 0; k < j; k++) { // statement 

I would say that it is n ^ 3, but I do not think it is right, because each for loop does not go from 1 to n. I did some tests:

n = 5 → 10

10 → 120

30 → 4060

50 → 19600

So, it should be between n ^ 2 and n ^ 3. I tried the summation formula and so, but my results are too high. Although n ^ 2 log (n), but it is also wrong ...

+6
source share
2 answers

This is O(N^3) . Exact formula (N*(N+1)*(N+2))/6

+3
source

Using Sigma Notation is an effective step-by-step methodology:

enter image description here

+4
source

All Articles