What is the complexity of $T(n) =3T((n-2)/2) + n^2$?

58 Views Asked by At

I have to find the complexity of a recursive function that has this form: $$T(n) =\left\{\begin{aligned} &3T((n-2)/2) + k_2n^2&&\text{ when }n > 1\\ &k_1 &&\text{ when } n = 1 \end{aligned}\right.$$ I have met $ T(n) = a*T(n/b) + n $, which resolves with Master Method, and $ T(n) = T(n-1) + n $ which resolves with iterative, but this is mixed, and I can't find a solution to it.

I have discovered that if I try it the iterative way starting from $T(n-2)$ and continuing with $ 3^k T( n/(2^k) )$, I end up with $ T(n-2) = 3^k*3T( n / (2^k2) ) + \sum_{i=0}^k( 3^i ( n /2^k - 2))$ but this leads nowhere. How can I find this solution?

2

There are 2 best solutions below

2
On

$$\bullet \quad \text{Note that: } T(n+2)=3T\bigg(\cfrac{n}{2} \bigg) +(n+2)^2=3T\bigg(\cfrac{n}{2} \bigg) +\Theta(n^2)$$ $$\text{Master Theorem } \implies T(n+2)=\Theta (n^2 )\iff T(n)=\Theta \big( (n-2)^2\big)=\Theta (n^2)$$ $$\implies \bbox[5px,border:1.5px solid red] {\color{black}{ T(n)=\Theta(n^2)}}$$

(note: $\log_2(3)<\log_2(4)=2$)

0
On

It'll need at least an $n^2$ behaviour, to match the last term on the right. Try $T(n)\sim cn^2$ so, for large $n$, $3T(n/2-1)\sim 3cn^2/4$. Equating $n^2$ coefficients, $c=3c^2/4+1$ i.e. $c=4$. On the other hand, a nonzero $n^p$ coeffiient can't be matched for $p>3$. So $T(n)\sim 4n^2\in\Theta(n^2)$.