expected value of final x using the following algorithm

321 Views Asked by At

It has a bit of pseudo code so i'll try to explain

x = 0
for i from 1 to n:
    if random() > 1/4:
       x = x + 5
    else:
       x = x - 1

the probability of random() returning a number larger than $\frac{1}{4}$ is $75\%$ and less than $\frac{1}{4}$ is $25\%$

what is the expected value of the final $x$?


attempt:

since x can either be the number of times random() $> \frac{1}{4}$ multiplied by $5$ or the number of times random() $< \frac{1}{4}- 1$, I've reduced the random variable $C$ is the number of times random returns a number greater than $\frac{1}{4}$ and the random variable $D$ as the number of times random returns a number smaller than $\frac{1}{4}$.

So $$E(X) = 5C -1D$$

Since I must preform this operation $n$ times:

$$E(X) = \sum_{i = 1} ^{n} = (5(.75) - 1(.25)) * n$$

$$E(X) = \frac{7}{2} \frac{(n(n+1))}{2}$$

Have I made a mistake in this?

2

There are 2 best solutions below

0
On BEST ANSWER

At each iteration, the expected value of $x$ changes by $$5\cdot 0.75 - 1\cdot 0.25 = \frac{7}{2},$$ so the expected value after $n$ iterations is $\frac{7}{2}n$.

0
On

Since I must preform this operation n times:

$$\begin{align}E(X) & =\sum_{i=1}^n (5(.75)−1(.25))∗n \\ & = \dfrac{7}{2} \frac{(n(n+1))}{2}\end{align}$$

Have I made a mistake in this?

Two mistakes.

Firstly, your summation index is $i$ and not $n$, and so $\sum\limits_{\color{red}{i}=1}^n n \neq \frac{n(n+1)}2$. (You've confused this with $\sum\limit_{\color{red}{i}=1}^n \color{red}{i} = \tfrac{n(n+1)}2$ )

Secondly, and more importantly, you should not sum over the index and multiply by $n$, as this is redundant.   You only need to do one or the other, not both.

$$\begin{align}E(X) & =\sum_{i=1}^n (5(.75)−1(.25)) \\ & = \dfrac{7}{2} \cdot n\end{align}$$