0
$\begingroup$

I want to find the bound for $T(n) = T (\frac{n}{5}) + \frac {n}{\log (n)}$. I tried with forward iteration and this is what i 've got

$T(1) = c$

$T(5^1) = c + 5^1$

$T(5^2) = c + 5^1 + (5^2)/2$

$T(5^3) = c + 5^1 + (5^2)/2 + (5^3)/3$

$T(5^k) = c + 5^1 + (5^2)/2 + (5^3)/3 + .. + (5^k)/k$

I am not able to solve this. Is there any formula to solve the above equation.

$\endgroup$
1
$\begingroup$

Let $f_k = T(5^k)$. The stated recurrence equation translates into $f_k = f_{k-1} + \frac{c}{k} 5^k$, where $c = \frac{1}{\log(5)}$. The solution is simple: $$ f_k = f_1 + \sum_{q=2}^{k} \frac{c}{q} 5^{q} = f_1 + c \sum_{q=2}^{k} \int_0^5 a^{q-1} \mathrm{d}a = f_1 + \frac{1}{\log 5} \int_0^5 \frac{a^k -a}{a-1} \mathrm{d}a $$

| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

This recurrence has an explicit solution when $T(0) = 0$ the same way as was done here. Let $$n = \sum_{k=0}^{\lfloor \log_5 n \rfloor} d_k 5^k$$ be the base $5$ digit representation of $n.$ We assume that the logarithm in the recurrence is in base $5$ and we take $\lfloor \log_5 n \rfloor+1$ to avoid dividing by zero, so that $$ T(n) = T(n/5) + \frac{n}{\lfloor \log_5 n \rfloor+1}.$$ It is not difficult to see that $$ T(n) = \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{1}{\lfloor \log_5 n \rfloor+1-j} \sum_{k=j}^{\lfloor \log_5 n \rfloor} d_k 5^{k-j} = \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{1}{5^j} \frac{1}{\lfloor \log_5 n \rfloor+1-j} \sum_{k=j}^{\lfloor \log_5 n \rfloor} d_k 5^k.$$ Note that $$\log_5 n - 1 < \lfloor \log_5 n \rfloor \le \log_5 n \quad \text{so that} \quad \log_5 n < \lfloor \log_5 n \rfloor +1\le \log_5 n +1,$$ which means that the absolute error in adding one to the floor of the logarithm is no worse than using the floor only.

Now to get an upper bound suppose all the digits are equal to four, which gives $$ T(n) \le \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{1}{5^j} \frac{1}{\lfloor \log_5 n \rfloor+1-j} 4 \sum_{k=j}^{\lfloor \log_5 n \rfloor} 5^k = \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{5^{\lfloor \log_5 n \rfloor+1}-5^j}{5^j} \frac{1}{\lfloor \log_5 n \rfloor+1-j} \\ = \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{5^{\lfloor \log_5 n \rfloor+1 -j}}{\lfloor \log_5 n \rfloor+1-j} - \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{1}{\lfloor \log_5 n \rfloor+1-j} = \sum_{j=1}^{\lfloor \log_5 n \rfloor+1} \frac{5^j}{j} - \sum_{j=1}^{\lfloor \log_5 n \rfloor+1} \frac{1}{j}.$$ For the lower bound take the leading digit to be one and the remaining digits to be zero. $$ T(n) \ge \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{1}{5^j} \frac{1}{\lfloor \log_5 n \rfloor+1-j} 5^{\lfloor \log_5 n \rfloor} \\ = \frac{1}{5} \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{5^{\lfloor \log_5 n \rfloor+1-j}}{\lfloor \log_5 n \rfloor+1-j} = \frac{1}{5}\sum_{j=1}^{\lfloor \log_5 n \rfloor+1} \frac{5^j}{j} .$$ These two bounds taken together imply $$ T(n) \in \Theta\left(\sum_{j=1}^{\lfloor \log_5 n \rfloor+1} \frac{5^j}{j} \right).$$ To get the asymptotics needs some rewriting $$ \sum_{j=1}^{\lfloor \log_5 n \rfloor+1} \frac{5^j}{j} = 5^{\lfloor \log_5 n \rfloor+1} \sum_{j=1}^{\lfloor \log_5 n \rfloor+1} \frac{5^{j-\lfloor \log_5 n \rfloor-1}}{j} = 5^{\lfloor \log_5 n \rfloor+1} \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{5^{-j}}{\lfloor \log_5 n \rfloor+1 -j} \\= \frac{5^{\lfloor \log_5 n \rfloor+1}}{\lfloor \log_5 n \rfloor+1} \sum_{j=0}^{\lfloor \log_5 n \rfloor} \frac{5^{-j}}{1 - \frac{j}{\lfloor \log_5 n \rfloor+1}} \\= \frac{5^{\lfloor \log_5 n \rfloor+1}}{\lfloor \log_5 n \rfloor+1} \sum_{j=0}^{\lfloor \log_5 n \rfloor} 5^{-j} \left( 1 + \left(\frac{j}{\lfloor \log_5 n \rfloor+1}\right) + \left(\frac{j}{\lfloor \log_5 n \rfloor+1}\right)^2 + \cdots\right).$$ The first term generated by this expansion is (take the first term of the geometric series) $$ \frac{5^{\lfloor \log_5 n \rfloor+1}}{\lfloor \log_5 n \rfloor+1} \frac{5}{4} \left( 1 - \frac{1}{5^{\lfloor \log_5 n \rfloor+1}} \right).$$ We may conclude that $$ T(n) \in \Theta \left(\frac{5^{\lfloor \log_5 n \rfloor+1}}{\lfloor \log_5 n \rfloor+1} \right) = \Theta \left(\frac{n}{\lfloor \log_5 n \rfloor+1} \right) = \Theta \left(\frac{n}{\log_5 n} \right) = \Theta \left(\frac{n}{\log n} \right).$$ Note that the second term in the upper bound gives a harmonic number on the order of $\log\log n.$

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.