On the number of consecutive tails when flipping a biased coin Say we flip a biased coin such that the probability of getting the same outcome in a row (head-head or tail-tail) is $p$. 
What is the probability of getting three or more tails consecutively out of $n$ flips (and alternatively out of infinite number of flips).
For example: TTT-H-TTT-HH-TTTT...
I am looking for:


*

*The fraction of tails that are in sections of size three or more.

*The expected size of sections with tails. 

 A: I’ll consider the case of an infinite string of coin tosses, as it’s easier.
Start with anon’s suggestion. Let $q$ be the probability that the coin comes up tails. Then the probability of getting two tails in a row must be $q^2$, and the probability of getting two heads in a row must be $(1-q)^2$, so you know that $p=q^2+(1-q)^2=2q^2-2q+1$, and therefore $$q=\frac14\left(2\pm\sqrt{4-8(1-p)}\right)=\frac12\left(1\pm\sqrt{2p-1}\right)\;.$$ One of the solutions is $q$; the other is $1-q$, the probability that the coin comes up heads. There’s no way to decide which is which without further information.
At any stage in the process the probability of a run of $n$ tails is $q^n(1-q)$, so the expected length of a run of tails is $\sum_{n\ge 0}nq^n(1-q)$. However, this includes runs of length $0$, which you don’t want to count, so an adjustment is needed. The probability of a run of length $0$ is $1-q\,$, so the probability of a run of positive length is $q$, and for $n>0$ the probability of a run of length $n$ given that the run has positive length is therefore $$\frac{q^n(1-q)}q=q^{n-1}(1-q)\;.$$ Thus, the expected length of a non-zero run of tails is $$\sum_{n\ge 1}nq^{n-1}(1-q)=(1-q)\sum_{n\ge 1}nq^{n-1}=\frac{1-q}{(1-q)^2}=\frac1{1-q}\;.$$ 

This is a fairly standard summation, but if you’re not familiar with it, just differentiate $$\sum_{n\ge 0}x^n=\frac1{1-x}\;.$$

For $k=1,\dots,n$ the probability that a given tail is the $k$-th of a run of $n$ tails is $q^{n-1}(1-q)^2$ (since we may ignore edge the effects at the beginning of the infinite string of tosses), so the probability that it belongs to a run of $n$ tails is $nq^{n-1}(1-q)^2$, and the probability that it belongs to a run of at least three tosses is $$\begin{align*}\sum_{n\ge 3}nq^{n-1}(1-q)^2&=(1-q)^2\sum_{n\ge 3}nq^{n-1}\\
&=(1-q)^2\left(\frac1{(1-q)^2}-(1+2q)\right)\\
&=q^2(3-2q)\;;
\end{align*}$$
this is the fraction of tails belonging to runs of three or more.
A: Call $q$ the probability to get a tail, hence $q$ solves $2q(1-q)=1-p$. Let $X_n$ denote the length of the run of consecutive tails just before time $n$ and $T_k=\inf\{n\geqslant0\mid X_n=k\}$. 
Your first question is asking for the probability of $[T_3\leqslant n]$. Note that $(X_n)_{n\geqslant0}$ is a Markov chain on $\{0,1,2,\ldots\}$, starting from $X_0=0$, with transition probabilities $p_{k,k+1}=q$ and $p_{k,0}=r$ with $r=1-q$.
The usual method to compute the distribution of $T_3$ applies. Call $t_k=\mathrm E_k(s^{T_3})$ for every $k\leqslant3$ and for a given $|s|\leqslant1$. Thus, one is interested in $t_0$ and one knows that $t_3=1$ and that, for every $k$ in $\{0,1,2\}$, $t_k=s(qt_{k+1}+rt_0)$.
This reads $t_0=qst_1+rst_0$, $t_1=qst_2+rst_0$ and $t_2=qs+rst_0$, hence $t_1=qs(qs+rst_0)+rst_0$ and $t_0=qs(qs(qs+rst_0)+rst_0)+rst_0$, that is,
$$
t_0=\frac{q^3s^3}{1-rs-qrs^2-q^2rs^3}.
$$
Introducing the three roots $s_1$, $s_2$ and $s_3$ of the polynomial $1-rs-qrs^2-q^2rs^3$, one gets for some coefficients $a_i$ that
$$
t_0=q^3s^3\sum_{i=1}^3\frac{a_i}{1-s/s_i}=q^3s^3\sum_{i=1}^3a_i\sum_{n\geqslant0}s^n/s_i^n,
$$
hence, by identification,
$$
\mathrm P(T_3=n+3)=q^3\sum_{i=1}^3a_i/s_i^{n},
$$
and finally,
$$
\mathrm P(T_3\leqslant n+3)=q^3\sum_{i=1}^3\frac{a_i}{s_i-1}(1-1/s_i^{n+1}).
$$
