Average and variance of flipping a coin A coin is flipped repeatedly with probability $p$ of landing on heads each flip.
Calculate the average $\langle n\rangle$ and the variance $\sigma^2 = \langle n^2\rangle - \langle n\rangle^2$ of the attempt n at which heads appears for the first time.
I have absolutely no idea where to start. How does one calculate $\langle n \rangle$ and $\langle n^2\rangle$? I have probability that head appears for the first time on the $n^{th}$ attempt to be $p(1-p)^{n-1}$ if that helps.
edit: Does it work if I treat it like a binomial distribution? Although I still don't understand how the expectation and variance come about. 
 A: This is a just a geometric distribution. If you aren't familiar with that, then I will derive the probability distribution. Let $X_n$ be iid $\operatorname{Ber}(p)$ random variables, i.e. $$\mathbb P(X_1=1)=p=1-\mathbb P(X_1=0),$$
and the $X_n$ are mutually independent. Then
$$X=\inf\{n\geqslant 1: X_n = 1\}. $$
For $n\geqslant 1$,
$$\mathbb P(X=n) = \mathbb P(X_{n}=1, X_{n-1}=0, \ldots, X_1=0). $$
Now, as the $X_n$ are independent, the above quantity is 
$$\mathbb P(X_{n}=1)\mathbb \prod_{i=1}^{n-1}\mathbb P(X_i=0)=p\prod_{i=1}^{n-1}(1-p)=p(1-p)^{n-1}. $$
Since
$$\sum_{n=1}^\infty \mathbb P(X=n)=\sum_{n=1}^\infty p(1-p)^{n-1} = p\sum_{n=0}^\infty(1-p)^n = p\cdot\frac1{1-(1-p)}=1, $$
this is indeed a valid probability distribution. To compute the mean, we have
$$
\begin{align*}
\mathbb E[X] &= \sum_{n=1}^\infty n\mathbb P(X=n)\\
&= \sum_{n=1}^\infty np(1-p)^{n-1}\\
&= p\sum_{n=0}^\infty (n+1)(1-p)^n\\
&= p\cdot\frac1{(1-(1-p))^2}\\
&= \frac1p.
\end{align*}$$
To compute the variance, it is easier to first compute $\mathbb E[X(X-1)]$:
$$
\begin{align*}
\mathbb E[X(X-1)] &= \sum_{n=1}^\infty n(n-1)p(1-p)^{n-1}\\
&= p(1-p)\sum_{n=0}^\infty n(n+1)(1-p)^n\\
&= p(1-p)\cdot\frac2{p^3}\\
&= \frac{2(1-p)}{p^2}.
\end{align*}
$$
Hence
$$
\begin{align*}
\operatorname{Var}(X) &= \mathbb E[X^2] - \mathbb E[X]^2\\
&= \mathbb E[X(X-1)] + \mathbb E[X] - \mathbb E[X]^2\\
&= \frac{2(1-p)}{p^2} + \frac1p - \frac1{p^2}\\
&= \frac{1-p}{p^2}.
\end{align*}
$$
A: Hint: 
\begin{align}E(X) &= \sum_{s \in S}p(s) \cdot X(s) &\text{ Expected Value of x}\\
Var(X) &= E(X^2) - E(X)^2 &\text{Variance of x}\end{align}
