Question:
$T(n) = 4T(\frac{n} {2})+n ,\hspace{0.5cm} if \hspace{0.5cm}n \geq 2 $
$\hspace{1.0cm} = 1 ,\hspace{2.2cm} if \hspace{0.5cm}n = 1 $
Solution by substitution method:
Generalized form:
$T(n) = 4^kT(\frac{n} {2^k})+n\sum_{n=1}^{k-1}2^i$
Until here you are good, but after this we can further simplify as below:
$\sum_{n=1}^{k-1}2^i$ is a finite geometric progression(GP), thus we use the formula:
$S_n=\frac{a_1(1-r^n)} {1-r} \hspace{0.5cm} when \hspace{0.5cm} r\neq1$
$S_n$ = sum of GP with n terms
$a_1$ = the first term
r = common ratio
n = number of terms
$T(n) = 4^kT(\frac{n} {2^k})+n(2^{k-1}-1)$
put $\frac{n} {2^k}= 1$
ie., $k=\log_2 n$
$T(n) = 1 ,\hspace{2.2cm} if \hspace{0.5cm}n = 1 $
$T(n) = 4^{\log_2 n}T(1)+n(\frac{n} {2}-1)$
$T(n) = n^{\log_2 4}+n(\frac{n} {2}-1)$
$T(n) = n^2+\frac{n^2} {2}-n$
Thus, $T(n)=O(n^2)$
Can you provide some guidance?
– JORGE Oct 19 '16 at 14:53