int res = 0;
for (int i = 0; i < x; i++)
{
res += i + function_5(i);
}
return res;
}
i guess it's O(n^2) but it doesn't feel right
It's exponential
Can you explain?
The educational way is to trace what happens when u call f(5), the easiest way is to try with f(1000) and the theoretical is to mess with the formula T(n) = 1 + \Sigma_{x = 0}^{n - 1} T(x) but it's difficult for me to solve it.
I just realized that the eqn is nothing but T(n) = 1 + 2 * T(n - 1) -_- That is T(n) = O(2^n), clearly exponential.
Обсуждают сегодня