0

$$T(n)=2T\left(\frac{n}{2}\right)+6n+\log(n)$$

Using the master theorem is seems to be both in case $2$ and case $3$.

Is there another way to approach this?

I tried this: $$T(n)=2\cdot 2\cdot (2T\left(\frac{n}{8}\right)+\frac{6}{8}n+\log(n)-\log(4))+3n+\log(n)-\log(2)+6n+\log(n)$$

Zacky
  • 27,674
gbox
  • 12,867
  • 1
    As usual, note that $R(k)=2^{-k}T(2^k)$ solves $$R(k)=R(k-1)+6+k2^{-k}\log2$$ hence $$R(k)=R(0)+6k+\Theta(1)$$ in particular, $$T(2^k)\sim6k2^k$$ from which you are probably expected to deduce (although the deduction is mathematically unsound) that $$T(n)\sim6n\log_2 n$$ – Did Feb 03 '19 at 16:59
  • @Did is it called a recurrence method? – gbox Feb 03 '19 at 17:00
  • "is it called a recurrence method?" Sorry, I do not understand your question. "It" might be called a simple and direct proof... – Did Feb 03 '19 at 17:01
  • @Did which method have you used? would like to read more about it – gbox Feb 03 '19 at 17:03
  • "which method have you used?" Is my comment not fully self-contained? – Did Feb 03 '19 at 17:04

1 Answers1

1

Similarly to this and this, we have: $$T(n)=2T\left(\frac{n}{2}\right)+6n+\lg n,\quad \ \lg n=\log_2 n$$ $$2T\left(\frac{n}{2}\right)=2\left(2T\left(\frac{n}{2^2}\right)+6\frac{n}{2}+\lg \frac{n}{2}\right)=2^2T\left(\frac{n}{2^2}\right)+6n+2\lg\frac{n}{2}$$ $$2^2T\left(\frac{n}{2^2}\right)=2^2\left(2T\left(\frac{n}{2^3}\right)+6\frac{n}{2^2}+\lg \frac{n}{2^2}\right)=2^3T\left(\frac{n}{2^3}\right)+6n+2^2\lg\frac{n}{2^2}$$ $$\dots$$ $$2^{q-1}T\left(\frac{n}{2^{q-1}}\right)=2^qT\left(\frac{n}{2^q}\right)+6n+2^{q-1}\lg \frac{n}{2^{q-1}}$$ We now consider the limit condition $$T\left(\frac{n}{2^q}\right)=T(1)\Rightarrow \frac{n}{2^q}=1\Rightarrow n=2^q \Rightarrow q=\lg n$$ Note that we only iterated the first term, of $T(n)$ and when we combine it back, we mustn't forget about the second and the third one. $$T(n)=2^{\lg n}T(1)+\sum_{k=0}^{q-1} 6n+\sum_{k=0}^{q-1} 2^k\lg \frac{n}{2^k}$$ $$=n \cdot T(1) +6n \cdot \sum_{k=0}^{q-1} +\sum_{k=0}^{q-1} 2^k(\lg n- \lg 2^k)$$ $$=n\cdot \Theta(1)+6n\cdot q+\lg n \sum_{k=0}^{q-1} 2^k -\sum_{k=0}^{q-1} 2^k \cdot k$$ Now using this formula and $q=\lg n$ we get: $$T(n)=\Theta(n)+6n\lg n+\lg n (2^q -1) -(q-1)2^{q+1}+q2^{q}-2$$ $$=\Theta(n)+6n\lg n +\lg n (n-1) -(\lg n-1) 2\cdot n +\lg n \cdot n -2$$ And since constants doesn't matter, we simply get: $$T(n)=\Theta(n\lg n)$$

Hopefully I haven't done any calculation mistakes, but this is a way to do it.

Zacky
  • 27,674