so I have this really complex nested loop that I need to find the complexity of. The code is given below:
1. int c = 0;
2. for (int i = 1; i <= n; i++)
3. for (int j = 1; j <= n; j++)
4. for (int k = 1; k <= i + j; k += 3)
5. c++;
6. return c;
So I know that the complexity is in O(n^3), but I need to know how to mathematically prove. Below shows the frequency of execution of each line.
1. 1
2. n
3. n(n-1)
4. No idea how to do this
5. No idea
6. 1
Can someone please help me out with the 4th and 5th step? It is really confusing as k goes from 1 to (i+j).