Me again.
This time I have a more general question.
Suppose I have the following code snippet:
int f(int k) {
int s=0;
for(int i=0; i<k*k; i++) {
s++;
}
return 2*k*k;
}
And the expression is:
f(n) * f(f(f(n)));
I am told that the complexity is O(n^2) + O(n^2) + O(n^4) + O(n^8)
I have several questions:
Why is there a plus sign when the function calls itself. Shouldn't it be "*" in between the last three terms?
What if the expression was
f(n) + f(f(f(n)));, would it still be the same?
And lastly and most importantly,
- What if it was this expression?
f(n) + f(z)*f(f(n))
This also confuses me very much. Most notably because there is a new variable z, and also because I am not sure that even if it was f(n) instead of f(z), should I multiply the complexity with f(f(n)) or add it to it.