# calculating variance of a random variable

Suppose you have a playlist consisting of four songs that you play in a smart shuffle mode. In this mode, after the current song is played, the next song is chosen randomly from the other three tracks. This ensures you never hear the same song twice in a row. Let X be the number of songs you listen to until you've heard all the four different songs.

I am trying to calculate the variance of X (Var(x)). But I am stuck on how to approach it in this case. I have calculated the expected value to be E(x) = 25/3 but I was looking at some class notes and think this problem is more than just doing the regular formula for variance using expectation. I am stuck trying to figure out how to approach this exactly.

Any help is appreciated, thank you.

EDIT FOR MORE CLARIFICATION:

This question has many parts which I've worked out.

1.How many sequences of 4 songs are there where no song plays twice in a row? If we label the songs {A, B, C, D}, then examples are ABCD and ABAB but not ABBA.

Answer: 108

2.What's the value of P(X = 4)?

Answer: 6/27

1. What's the value of P(X = 5)

Answer: 5/7

1. What is the value of E(X)?

Answer: 25/3

1. Var(X) = ?

This is where I am stuck, and need clarification/ help.

• What do you mean? I added more for clarification. This does map to real numbers. – userunknown Apr 15 '14 at 14:21
• Uh, sorry, I thought $X$ was the song that's played, not the number of songs. Sorry. To compute $Var(X)$, you can use that $Var(X) = E(X^2) - (E(X))^2$. Since you already found $E(X)$, I guess you'll find $E(X^2)$ too. – fgp Apr 15 '14 at 14:27
• I do not think I can use that formula if you take a look at these slides: people.cs.umass.edu/~mcgregor/240S13/lec15.pdf – userunknown Apr 15 '14 at 14:35
• You can always use this formula! Sometimes there might be an easier way, particularly if computing $E(X^2)$ is hard, but the formula is never wrong. – fgp Apr 15 '14 at 14:37

## 1 Answer

First off, your probabilities are wrong.

$P(X=1)=1/4$

Now

$P(X=2)= 3/4 \times 1/3=1/4$

$P(X=3)= 3/4 \times 2/3 \times 1/3= 1/4 \times (2/3)$

$P(X=4) = 3/4 \times 2/3 \times 2/3 \times 1/3 = 1/4 \times (2/3)^2=1/9 \neq 6/27$.

To get the expectation you just compute

$$EX = \sum_{j=1}^\infty P(X=j) j.$$

To get the variance you compute

$$EX^2 = \sum_{j=1}^\infty P(X=j) j^2,$$

and then

$$VX=EX^2-(EX)^2,$$

as suggested in one of the comments.

Given that this is homework I'll let you fill in the details.