2
$\begingroup$

Solve $n + n/2 + n/4 + n/8 + \dots$ up to $\log n$ terms

This looks like Harmonic series. But I couldn't find a formula to calculate the sum of the series up to $\log n$ terms. Can anyone solve it please.

3 Answers 3

7

It's $n$ times the geometric series $1 + \frac{1}{2} + \frac{1}{4} + \frac{1}{8} + \dots \frac{1}{2^{\log n - 1}}$. Do you know how to find the value of a geometric sum?

  • 1
    @VISHNUVIVEK The geometric sum formula is pretty easy. Can you include the calculations in your question so that others can check that it corresponds to the sum you wrote (or vice-versa)?2012-11-26
2

I'll start by making some simplifications. Since you didn't specify the base for your log function, I'll assume that it is some integer $b>1$. Also, since it wasn't completely clear what you meant by "up to $\log n$ terms", I'll assume that we want $\log n$ to be an integer. Neither of these assumptions are necessary; they just make calculations easier.

Since $\log_bn$, the number of terms, is assumed to be an integer, we must have $n=b^k$ for some integer $k>0$. Then your expression will be $ b^k(\underbrace{1+\frac{1}{2}+\frac{1}{4}+\cdots + \frac{1}{2^{k-1}}}_{k\text{ terms}})=b^k\left(\frac{1-(1/2^k)}{1-(1/2)}\right)=2b^k\left(1-\frac{1}{2^k}\right) $ by the formula for the sum of a geometric series. Now since we assumed $n=b^k$ we'll see that your sum will be $ 2b^k\left(1-\frac{1}{2^k}\right)=2n\left(1-\frac{1}{2^{\log_bn}}\right)=2n\left(1-\frac{1}{n^{\log_b2}}\right) $ using the useful and frequently-forgotten identity $a^{\log_bc}=c^{\log_ba}$. As a reality check, if $b=2$ and $k=4$ (so $n=2^4=16$) we'll have the sum $ 16\left(1+\frac{1}{2}+\frac{1}{4}+\frac{1}{8}\right)=30=32\left(1-\frac{1}{16}\right)=2\cdot16\left(1-\frac{1}{16^{\log_22}}\right) $

2

Let us assume that $n=2^k$ and let your sum be $S=\sum_{i=0}^k n 2^{-k}$. Then $S$ denotes the number of nodes in a complete balanced binary tree of height $k$ with $n$ leaves. Such a tree has $2^{k+1}-1$ nodes, which can be easily shown by induction. Thus in your case we have $S=2n-1$.

  • 0
    For this kind of thing I usually write the numbers in binary. e.g. $32 = {10000}_2$. 32 / 2 = 32 >> 1 = {1000}_2 (shift right one place), likewise n 2^{-k} = n >> k, so $32 (1 + 1/2 + 1/4 + ... ) = 10000 + 1000 + 100 + 10 + 1$, if you take that number and add another one, it will be carry all over until it settles putting one more one to the left. In this case: 11111 + 1 = 100000 (which is effectively multiplying 32 by 2). So 100000 - 1 = 11111, and the same can be done for any integer power of two.2014-10-15