Expected absolute difference between 1's and 0's

234 Views Asked by At

Given a random binary string with size n, what is the expected absolute difference between the number of ones and zeros? no need for an accurate expression just an asymptotical bound.

My answer (I'm looking for a better one) is:

let the string be of size $2n$ (for comfortability). let $X$ be the absolute difference. $X$, of course, must be even

$X=2k$ if and only if the number of ones is $n+k$ or the number of zeros is $n+k$. I.e $\Pr(X=2k) = 2\cdot \binom{2n}{n+k}\cdot 2^{-2n}$.

so $E[X] = \sum _{k=0}^n2k\cdot Pr(X=2k) = \frac{4}{4^n}\sum _{k=0}^n\binom{2n}{n+k}k$

using wolfram alpha I can calculate the sum above and get that $E[X] =\Theta(\sqrt n)$ but I'm looking for a simpler solution

1

There are 1 best solutions below

4
On BEST ANSWER

For a string of length $2n$, the distribution of the number $Y_n$ of ones is binomial $(2n,\frac12)$. The number of zeroes is $2n-Y_n$ hence the absolute difference between the number of ones and zeroes in a string of length $2n$ is $X_n=|Y_n-(2n-Y_n)|=2|Y_n-n|$.

By the central limit theorem, $Z_n=(Y_n-n)\sqrt{2/n}$ converges in distribution to $Z$ standard normal.

This result (does not imply per se but) can be enhanced to the convergence of the moments of $Z_n$ to the moments of $Z$. Thus, $$E(X_n)=2\sqrt{n/2}E|Z_n|\sim \sqrt{2n}E|Z|=\sqrt{2n}\sqrt{2/\pi}=2\sqrt{n/\pi}$$ This confirms that $E(X_n)=\Theta(\sqrt n)$, and refines this estimate into the asymptotics

$$\lim_{n\to\infty}\frac{E(X_n)}{\sqrt n}=\frac2{\sqrt\pi}$$