What is $$\sum_{i=0}^{\log n}i\cdot 2^i\:?$$ I know it's $O(n\cdot\log n)$ but how do you calculate this sum?
-
Welcome to MSE! Please use the mathjax basic tutorial, review the meta read and enhance your question. It helps to include context (i.e., your attempts, motivation, etc). – Jessie Mar 15 '21 at 18:20
-
The summation doesn't make sense unless $\log n$ is an integer, in which case, why not just call it $n$? – ndhanson3 Mar 15 '21 at 18:26
-
There are at least two ways to go about this. Either use “summation by parts”. Or consider the sum of $ix^i$ for a variable $x$ and integrate it all over $x$. – Milten Mar 15 '21 at 18:29
-
Lets call the summation S and the subtract it from 2S. You will see that all the i's at the front will be reduced to one leaving you with a simple geometric series plus some additional terms. – shahrOZe Mar 15 '21 at 18:42
2 Answers
Define $f_{N}(t)$ such that $$f_{N}(t) := \sum_{i=0}^{N} 2^{it}$$ this is a geometric sum which has the solution $$f_{N}(t) = \frac{2^{Nt} - 1}{2^{t} - 1}$$ Now your sum is $\frac{1}{\ln 2}f_{\log n}'(1)$ so: $$\sum_{i=0}^{\log n}i\cdot 2^i = \frac{1}{\ln 2}f_{\log n}'(1) = \frac{1}{\ln 2}\frac{d}{dt}(\frac{2^{(\log n)t} - 1}{2^{t} - 1})|_{t=1}$$

- 416
- 2
- 12
$\newcommand{LG}[1]{\left\lfloor \log{#1}\right\rfloor}$For $x\ne 1$, $$\sum_{k=0}^n k x^k=x\frac{d}{dx}\frac{x^{n+1}-1}{x-1}=x\frac{(n+1)x^n(x-1)-x^{n+1}+1}{(x-1)^2}=\\=\frac{nx^{n+2}-(n+1)x^{n+1}+x}{(x-1)^2}$$
Therefore $$\sum_{k=0}^{\LG n}k2^k=\frac{4\LG n2^{\LG n}-2\left(\LG n+1\right)2^{\LG n}+2}{(2-1)^2}=\\=2\LG n2^{\LG n}-2^{\LG n}+2$$
Now I presume that by $\log n$ you mean $\log_2n$, in which case we can see by $0\le\log n-\LG n\le 1$ that the quantity is in $\Theta(2^{\log n}\log n)=\Theta(n\log n)$.
If $\log n$ doesn't mean $\log_2n$, then the quantity is actually in $\Theta(n^{\log 2}\log n)$, and therefore not necessarily in $O(n\log n)$ (though it still is if you are working with $\log 2<1$).