1

$T(n) = T(n-2)+T(n-3)+2T(n/3)$ and $T(n)=1$ for $n<4$. I tried to compute the complexity of $T(n) = T(n-2)+T(n-3)+2T(n/3)$ using the recursion tree but it's not clear enough for me to make a guess and demonstrate it by induction? also, it should be computed given both upper and lower bound.

Sydney.Ka
  • 69
  • 5

2 Answers2

1

You can notice that $T(n) < 3T(n-2)$. This gives you the complexity as $O(3^{n/2})$. You can also observe that $T(n) > 2T(n-3)$. This gives you the complexity as $\Omega(2^{n/3})$. Now, you can at least tell that the complexity is an exponential one.

David Richerby
  • 82,470
  • 26
  • 145
  • 239
Rishabh Jain
  • 121
  • 3
1

Summary: $T(n) = \Theta(\alpha^n)$, where $\alpha=\sqrt[3]{\frac{9+\sqrt{69}}{18}}+\sqrt[3]{\frac{9-\sqrt{69}}{18}}\approx 1.324718$.

Find $\alpha$

Let $\alpha$ be the unique positive root of $x^3=x+1$.

We can solve the equation manually by the standard method, letting $x=w+\frac 1{3w}$ and solving $w$. If we trust the online calculators or you can use some software package such as MatLab, Maple, Wolfram Alpha or Python numpy.root, you can find all the exact roots or the approximate roots. In fact, since all we need is a positive root, we could also cheat a bit by just verifying directly the following quantity is a root. $$\alpha=\sqrt[3]{\frac{9+\sqrt{69}}{18}}+\sqrt[3]{\frac{9-\sqrt{69}}{18}}\approx 1.324718$$

Reference function $S$

Let $S(n)= S(n-2)+S(n-3)$ and $S(n)=1$ for $n<4$.

Claim: $\frac{\alpha^n}{3}<S(n)<\alpha^n$ for all $n\ge1$.

Proof by mathematical induction on $n$.

  • The base case when $1\le n\le3$ is easy since $1<\alpha$ and $\alpha^3<3$.
  • Since $\alpha^3=\alpha+1$, the induction step is easy. Assume the claim is true when $n\le k-1$ for some $k\ge3$. Then $$S(k)=S(k-2)+S(k-3)>\frac{\alpha^{k-2}}{3}+\frac{\alpha^{k-3}}3=\frac{\alpha^k}3$$ $$S(k)=S(k-2)+S(k-3)<\alpha^{k-2}+\alpha^{k-3}=\alpha^k$$

Last Trick

Claim One: $S(n)\le T(n)$ for all $n\ge1$.

Proof: It is easy to prove by mathematical induction that $T(n)>0$ for all $n\ge1$. $S(n)\le T(n)$ follows easily by mathematical induction.

Lemma: there exists a constant $c>0$ such that for all $n\ge c$, $\alpha^{\frac{2n}3} > 3n^2$.

Proof. This is obvious since any growing exponential function grows faster than any polynomial, a well-known fact that is (almost) proved in this answer. (We can take c=72, for example.)

Claim Two: There exist a constant $d>0$ such that $T(n)<d(1-\frac1n)S(n)$ for all $n\ge1$. (That factor $1-\frac1n$ is the "last trick".)

Proof. Let $c>4$ be a constant as in the lemma. Let $d=1+2\max_{1\le n<c}(T(n))>1$. Let us prove $T(n)<d(1-\frac1n)S(n)$ by mathematical induction on $n$.

  • The base case when $n<c$. $T(n) < d/2 \le d(1-\frac1n) \le d(1-\frac1n)S(n)$.
  • Suppose the inequality is true for all $n\le k-1$, where $k\ge c$. Then

$$ \begin{aligned} T(k)=& T(k-2) + T(k-3) + 2T(k/3)\\ \lt& d(1-\frac1{k-2})S(k-2) + d(1-\frac1{k-3})S(k-3) + 2d(1-\frac1{\frac k3})\alpha^{\frac k3} \\ \lt&d(1-\frac1{k-2})(S(k-2)+S(k-3)) + 2d\alpha^{\frac k3}\\ =&d(1-\frac1{k-2})S(k) + 2d\alpha^{\frac k3}\\ =&d(1-\frac1{k})S(k) - \frac{2d}{(k-2)k}S(k)+ 2d\alpha^{\frac k3} \\ \lt&d(1-\frac1{k})S(k) - \frac{2d}{(k-2)k}\frac13\alpha^k+ 2d\alpha^{\frac k3} \\ =&d(1-\frac1{k})S(k) - \frac{2d\alpha^{\frac k3}}{3(k-2)k}(\alpha^{\frac {2k}3} - 3(k-2)k)\\ \end{aligned}$$

Since $\alpha^{\frac {2k}3} - 3(k-2)k \gt \alpha^{\frac {2k}3} - 3k^2\gt0$, we obtain $T(k) \lt d(1-\frac1{k})S(k)$.

Claim Three: $T(n)=\Theta(\alpha^n)$

Proof: This follows immediately from the two above claims since $\frac{\alpha^n}{3}<S(n)<\alpha^n$ and $d(1-\frac1n)\le d$.

John L.
  • 39,205
  • 4
  • 34
  • 93