I know that recursive equation of this algo is
$T\left ( n \right )=2T\left ( \frac{n}{2} \right )+2 $
Given that $T\left ( 1 \right )=0,T\left ( 2 \right )=1 $
and its solution is also given here, ijust want to clear my doubt where i am stuck at.. I solved this eqtn as--:
$\Rightarrow T\left ( n \right )=2\left ( 2*T\left ( \frac{n}{4} \right )+2 \right )+2 $
$\Rightarrow T\left ( n \right )=2^{2}+T\left ( \frac{n}{2^{2}} \right )+2^{2}+2^{1}$
$\vdots$
$\Rightarrow T\left ( n \right )=2^{k}*T\left ( \frac{n}{2^{k}} \right )+2^{k}+\cdots 2^{2}+2^{1}$
Taking $T\left ( 1 \right )=0 $
$\frac{n}{2^{k}}=1 \Rightarrow k=\log_{2}n $
And our equation becomes
$2^{k}+2^{k-1}+\cdots 2^{2}+2^{1} = \frac{2*\left ( 1-2^{k} \right )}{1-2}=2n-2 ,\left \{ 2^{k}=2^{log_{2}n}=n\right \} $
But answer is $\frac{3*n}{2}-2$..please correct me in this equation.