0

I need your help with time complexity.

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

and I had to do the same thing using recursion in C#, so I came up with this :

 public static int F1(int n)
{
    if (n > 1) return F1(n - 2) + 10 * F1((int)Math.Pow((n/6),2)) + 6 * F1(n / 7) + ((int)Math.Pow(n,4) / 5);
    else return 2;
}

I need help calculating the time complexity of this algorithm, and I don't even know where to start and how to do it, could you please give me a hand?

Thank you for any kind of help.

Raphael
  • 72,336
  • 29
  • 179
  • 389
Daniel
  • 1
  • 1
  • Try running your implementation. If $n$ is large enough then it will never stop. As an aside, when you want to square an integer, just use n * n. – Yuval Filmus Apr 09 '17 at 06:05
  • Try solving the recurrence $F(n) = F(n/6)^2$ instead (with base case $F(1)=2$). If $n=6^m$ then the solution is $2^{2^m} = 2^{n^{\log_6 2}}$. Your recurrence should have similar order of growth. – Yuval Filmus Apr 09 '17 at 06:07
  • @YuvalFilmus Thanks for the reply. I've noticed that with a large n I'm getting a "stack overflow" error, but I think there is nothing I can do about it, right? Speaking about solving a time complexity, I'm still kind of lost. Are you saying that time complexity for this whole recurrence is $$2^{n^{\log_6 2}}$$ ? – Daniel Apr 09 '17 at 09:00
  • You use $F((n/6)^2)$ instead of $(F(n/6))^2$. That's why you get a stack overflow. – Yuval Filmus Apr 09 '17 at 09:16
  • Regarding the asymptotics, I suspect it is similar to what I wrote, up to mild multiplicative factors. – Yuval Filmus Apr 09 '17 at 09:17

0 Answers0