Use mathematical induction to show that when n is an exact power of 2, the solution of the recurrence:\[T(n) = 2 \ \ if\ \ n = 2\]\[2T(n/2)+n\ \ \ \ if\ \ \ n = 2^k,\ \ \ for\ \ k > 1\] is T(n) = nlg(n)
T(n) is what?
nlog(n) ?
\(nlog_2(n)\)
Base 2 I guess?
you can prove it without using induction
I want to prove the relation for \(2^n\), \(n\ge 1\) using induction: First for n=1, \(T(2^1)=2=2\log_{2}(2)\). Now, assume the relation is true for n=k, that is: \[T(2^k)=2^k\log_{2}(2^k)=k\cdot2^k\] Lets show that this assumption implies that it's also true for n=k+1: \[T(2^{k+1})=2T(\frac{2^{k+1}}{2})+2^{k+1}=2T(2^k)+2^{k+1}=2k\cdot2^k+2^{k+1}\] \[=(k+1)2^{k+1}=2^{k+1}\log_{2}(2^{k+1}). ■\]
\[\begin{align} \text{if } T(n) &= n\log_2(n)\\ \text{then } T(n/2) &= \frac{n}{2}\log_2(\frac{n}{2})\\ &=\frac{n}{2}(\log_2(n)-\log_2(2))\\ &=\frac{n}{2}(log_2(n)-1)\\ \therefore 2T(n)&=n\log_2(n)-n\\ &=T(n)-n\\ \therefore T(n)&=2T(n/2)+n \end{align}\]
3rd from last line was wrong on left hand side - should be 2T(n/2)=
and this seems to have no restriction of \(n=2^k\) on it
have I made a mistake somewhere?
Join our real-time social learning platform and learn together with your friends!