[Math] Time Complexity of $T(n)=T(n-2)+\frac{1}{\log(n)}$

computational complexity

Solve $T(n)=T(n-2)+\frac{1}{\log(n)}$ for $T(n)$.

I am getting the answer as $O(n)$ by treating $1/\log(n)$ as $O(1)$. The recursive call tree of this is a lop-sided tree of height $n$. Hence, considering the amount of work done in each step, the answer comes out to be $O(n)$.
Please verify my answer, and tell me if I am correct.

Best Answer

If $T(n)=T(n-2)+\frac{1}{\log(n)}$, then $$ T(n)=\left\{\begin{array}{}T(0)+\sum_{k=1}^{n/2}\frac{1}{\log(2k)}&\text{if }n\text{ is even}\\T(1)+\sum_{k=1}^{(n-1)/2}\frac{1}{\log(2k+1)}&\text{if }n\text{ is odd}\end{array}\right.\tag{1} $$ Note that $$ \begin{align} \sum_{k=1}^{(n-1)/2}\frac{1}{\log(2k+1)} &\le\frac{1}{\log(3)}+\int_1^{(n-1)/2}\frac{\mathrm{d}x}{\log(2x+1)}\\ &=\color{#C00000}{\frac{1}{\log(3)}+\frac12\int_3^8\frac{\mathrm{d}x}{\log(x)}}+\frac12\int_8^n\frac{\mathrm{d}x}{\log(x)}\tag{2} \end{align} $$ and $$ \begin{align} \sum_{k=1}^{n/2}\frac{1}{\log(2k)} &\le\frac{1}{\log(2)}+\int_1^{n/2}\frac{\mathrm{d}x}{\log(2x)}\\ &=\color{#C00000}{\frac{1}{\log(2)}+\frac12\int_2^8\frac{\mathrm{d}x}{\log(x)}}+\frac12\int_8^n\frac{\mathrm{d}x}{\log(x)}\tag{3} \end{align} $$ For $n\ge8$, we have that $\log(x)\le2(\log(x)-1)$, thus $$ \begin{align} \frac12\int_8^n\frac{\mathrm{d}x}{\log(x)} &\le\int_8^n\frac{(\log(x)-1)\mathrm{d}x}{\log(x)^2}\\ &=\frac{n}{\log(n)}\color{#C00000}{-\frac{8}{\log(8)}}\tag{4} \end{align} $$ Combining $(1)$ though $(4)$, we get that $$ T(n)\le\color{#C00000}{C}+\frac{n}{\log(n)}=O\left(\frac{n}{\log(n)}\right)\tag{5} $$

Related Question