I have a very stupid question, it seems that I've forgotten most of my math and can't figure this out.
Considering the following,
For example consider the recurrence T(n) = 2T(n/2) + n
We guess the solution as T(n) = O(nLogn). Now we use induction
to prove our guess.
We need to prove that T(n) <= cnLogn. We can assume that it is true
for values smaller than n.
T(n) = 2T(n/2) + n
<= cn/2Log(n/2) + n
= cnLogn - cnLog2 + n
= cnLogn - cn + n
<= cnLogn
Now, I'm at a loss to how 2T(n/2) became cn/2Log(n/2). I'm guessing that n was replaces by cnLogn. But how does the rest of it follow?
Thanks.
We can take $c\ge 1$ without loss of generality.
Then \begin{eqnarray}T(n) &\le& 2 c {n \over 2} \log_2 {n \over 2} + n \\ &\le& cn (\log_2 {n \over 2} +1) \\ &=& cn ( \log_2 n -1 + 1) \\ &=& cn \log_2 n \end{eqnarray}