Time Complexity Recursion

128 Views Asked by At

I have this recursive function: $$ F(n) = \left\{ \begin{array}{l l} F(n-2) + 10 F\big(\lfloor\frac{n}{6}\rfloor\big)^2 + 6 F\big(\lfloor \frac{n}{7} \rfloor \big) + \frac{n^4}{5} & \text{if } n > 1\\ 2 & \text{otherwise}\\ \end{array} \right. $$

And I need to calculate its time complexity. Could you please guide me on how to do it? I assume time grows exponentially, maybe it is $ O(3^n)$ because each time this function calls itself 3 times more? (Given we implement this by simple recursion)

1

There are 1 best solutions below

4
On BEST ANSWER

If we take the floor of $n/6$ and $n/7$, $O(3^n)$ looks too high to me.

One straight-forward algorithm is to calculate every point starting from $1$ to $n$ (and store all the results in an array), and then you get complexity of $O(n)$

EDIT

If you brutal force by implementing this using simple recursion approach, yes, it is $O(3^n)$, because you cannot re-use any results you calculated when arriving each single point of $F$.

In that case, for each $F(n)$, you need to recurse for $O(n)$ layers, and within each layer, you spawn three function calls that each will spawn another three function calls for the next layer of recursion calls. Thus it is $O(3^n)$