Expectation and Variance of Binary String

combinatoricsdiscrete mathematicsexpected valueprobabilityprobability distributions

I've been working on the following problem:

Assume a computer generates binary string of length 14 at random. Let $K$ be the random variable that is equal to the number of 0’s in the string plus twice the number of
ones in the string. Calculate $E(K)$ and $Var(K)$.

Now since each individual bit has a 50% chance of either being a 1 or 0, I found the expected number of 0's to be $14*1/2=7$. I'm assuming this problem involves the fact that $E[X+2Y] = E[X] + 2E[Y]$.

But if $X$ represents 0's and $Y$ represents 1's, I get that: $E[X + 2Y] = 7 + 2*7$ = $21$.

However, the length of the string is only $14$, which is why I am lost calculating the expected value.

Any help, hints, and advice would be much appreciated!

Best Answer

Let's do the general case, with length $n$ instead of just length $14$.

We let $X$ be the random variable which counts the number of $0's$ in the string and, of course, $K$ is the random variable defined in the problem.

We remark that the number of $1's$ must be $n-X$ so we have $$K=X+2(n-X)=2n-X$$

Thus we immediately see that $$E[K]=2n-E[X]=2n-\frac n2=\frac {3n}2$$

As to the variance, shifting each value by a constant does not change the variance so $$\text {Var}(K)=\text {Var}(-X)=\text {Var}(X)=\frac n4$$

Related Question