1

I am struggling with the following equation for one week! Please help me solve it.

$$T(n)=T(\frac{n}{2})+\frac{n}{logn}$$

So far, I have come to the equation $T(n)=\Sigma \frac{2^x}{x}$

2 Answers2

1

Using Master theorem, you can choose $c=\frac{1}{2}>0=log_21$, and you get: $f(n)=\frac{n}{logn}=\Omega(n^{\frac{1}{2}})$. In this case the theorem would yield: $T(n)=\Theta(\frac{n}{logn})$.

0

Suppose you have $T(0)=0$ and $T(1) = 1$ and your recurrence for $n>1$ is $$T(n) = T(\lfloor n/2 \rfloor) + \frac{n}{\lfloor\log_2 n \rfloor}.$$ By unrolling the recursion we find the exact formula for $n\ge 2:$ $$T(n) = 1 + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{1}{\lfloor\log_2 n \rfloor - k} \sum_{j=k}^{\lfloor\log_2 n \rfloor} d_j 2^{j-k}$$ where the digits $d_j$ are from the binary representation of $n$ given by $$n = \sum_{j=0}^{\lfloor\log_2 n \rfloor} d_j 2^j.$$ We now compute upper and lower bounds. For an upper bound consider a string of one digits, which gives $$T(n)\le 1 + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{1}{\lfloor\log_2 n \rfloor - k} \sum_{j=k}^{\lfloor\log_2 n \rfloor} 2^{j-k} = 1 + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{1}{\lfloor\log_2 n \rfloor - k} \left(2^{\lfloor\log_2 n \rfloor+1-k} -1\right) \\ = 1 - H_{\lfloor\log_2 n \rfloor} + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{2^{\lfloor\log_2 n \rfloor+1-k}}{\lfloor\log_2 n \rfloor - k} = 1 - H_{\lfloor\log_2 n \rfloor} + 2\times \sum_{k=1}^{\lfloor\log_2 n \rfloor}\frac{2^k}{k}.$$ To extract the asymptotics from this we use the next-to-last form, which gives $$1 - H_{\lfloor\log_2 n \rfloor} + \frac{2^{\lfloor\log_2 n \rfloor+1}}{\lfloor\log_2 n \rfloor} \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{2^{-k}}{1 - \frac{k}{\lfloor\log_2 n \rfloor}} \\ = 1 - H_{\lfloor\log_2 n \rfloor} + \frac{2^{\lfloor\log_2 n \rfloor+1}}{\lfloor\log_2 n \rfloor} \left( \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} 2^{-k} + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{k 2^{-k}}{\lfloor\log_2 n \rfloor} + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{k^2 2^{-k}}{\lfloor\log_2 n \rfloor^2} +\cdots\right) \\= 1 - H_{\lfloor\log_2 n \rfloor} \\+ \frac{2^{\lfloor\log_2 n \rfloor+1}}{\lfloor\log_2 n \rfloor} \left( \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} 2^{-k} + \frac{1}{\lfloor\log_2 n \rfloor}\sum_{k=0}^{\lfloor\log_2 n \rfloor - 1}k 2^{-k} + \frac{1}{\lfloor\log_2 n \rfloor^2}\sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} k^2 2^{-k} +\cdots\right).$$ The sums all converge to numbers so we finally get $$1 - H_{\lfloor\log_2 n \rfloor} + \frac{2^{\lfloor\log_2 n \rfloor+1}}{\lfloor\log_2 n \rfloor} \left(2 + \frac{2}{\lfloor\log_2 n \rfloor} + \frac{6}{\lfloor\log_2 n \rfloor^2} + \frac{26}{\lfloor\log_2 n \rfloor^3} +\cdots\right).$$ Continuing with the lower bound which occurs for a one digit followed by a string of zeroes we get $$T(n)\ge 1 + \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{1}{\lfloor\log_2 n \rfloor - k} 2^{\lfloor\log_2 n \rfloor-k} = 1 + \sum_{k=1}^{\lfloor\log_2 n \rfloor} \frac{2^k}{k}.$$ To extract the asymptotics we work with the next-to-last form, which gives $$1 + \frac{2^{\lfloor\log_2 n \rfloor}}{\lfloor\log_2 n \rfloor} \sum_{k=0}^{\lfloor\log_2 n \rfloor - 1} \frac{2^{-k}}{1 - \frac{k}{\lfloor\log_2 n \rfloor}}.$$ The sum is the same as before so we finally have the lower bound $$1 + \frac{2^{\lfloor\log_2 n \rfloor}}{\lfloor\log_2 n \rfloor} \left(2 + \frac{2}{\lfloor\log_2 n \rfloor} + \frac{6}{\lfloor\log_2 n \rfloor^2} + \frac{26}{\lfloor\log_2 n \rfloor^3} +\cdots\right).$$ Note that these bounds are attained. Joining the upper and the lower bound we have a complexity of $$T(n)\in\Theta\left(\frac{2^{\lfloor\log_2 n \rfloor}}{\lfloor\log_2 n \rfloor}\right) = \Theta\left(\frac{n}{\log n}\right)$$ which to be clear about it could have been spotted by inspection, but there is no harm in doing a formal proof.

Remark. The reader may profit from studying the calculation at this MSE link which is similar but just different enough to create a learner's effect. (Unfortunately it has $j$ and $k$ in the explicit formula reversed but this does not warrant editing everything I have just written.)

Observation. When using the asymptotic expansion for fixed $n$ care must be taken because the coefficients eventually outgrow the inverse powers of the logarithm. The best value to use is the one just before the expansion starts diverging.

Addendum. The sequence of coefficients $2,2,6,26,\ldots$ in the asymptotic expansion is examined in detail at the following MSE link.

Marko Riedel
  • 61,317