# Finding expected number of trials until we get head given density function?

Suppose we flip a coin with a random probability of Heads $P$ that has density $f(p) = 6p(1−p),\; p \in [0, 1]$. If we keep on flipping this coin until we get a single Heads, what is the expected number of trials until we get our Head?

So my approach was to use the expected value formula to get $E[X]$ where $X$ is the number of trials until we get head, but I don't think it is the correct way and I need some tips on how to approach this problem. Any help would be great, thanks.

Let $N$=no. of trials. Note that $N|P=p\in Geo(p)$.
So $E(N)=E(E(N|P))$ is what we will use.
$E(N|P)=\dfrac{1}{P}$ as is well known.
Then $E(E(N|P))=E(\dfrac{1}{P})=\int_0^1 6(1-p)dp=6-3=3$
• BTW. This is known as the Law of Iterated Expectation (sometimes the Law of Total Expectation). $$\newcommand{\E}{\operatorname{\sf E}}\E(X) = \E(\E(X\mid Y))$$ – Graham Kemp Aug 5 '15 at 0:45