# Probability of tossing a biased coin without having k heads consecutively in a row

I got asked by a friend this question; I have a coin, the probability of receiving a head by tossing is $p$ and tail $1-p$. I have to toss it $n$ times without getting $k$ heads in a row. What is the probability for this to occur?

This is the generalisation of the problem where the coins are unbiased (i.e $1/2$ chance of getting a head or a tail) and two heads don't occur in a row and the coin is tossed 10, 11.. or any number of times.

I am thinking along the lines of something like this:

If $F_n$ be the probability I can have a toss sequence of $n$ tosses meeting the requirements, then if the first coin is tails, the $n-1$ remaining tosses can meet the requirements with a probability of $F_{n-1}$, so the whole thing can be done with $(1-p)F_{n-1}$ probability . If the first $k-1$ coins are head then the $k^{th}$ one must be tails and the next $n-k$ can be done with a probability of $F_{n-k}$, so the whole thing has a probability of $p^{k-1}.(1-p).F_{n-k}$ , doing the same thing for first $k-2$ being heads(and next one a tail), for first $k-3$ being heads(and next one a tail), ...., for first $1$ being a head(and next one a tail) I get:

$F_{n} = (p^{k-1}.(1-p).F_{n-k}) + (p^{k-2}.(1-p).F_{n-k+1}) + ... + (p^1.(1-p).F_{n-2}) + (1-p).F_{n-1}$ , for $n>k$

i.e $F_{n} = (1-p) \sum_{0\le x<k} (p^x . F_{n-x})$

I think for the base cases i.e from $F_1$ to $F_{k-1}$ all the values have a probability of $1$ since we can have any side of coin without breaking the requirement.

This is getting a bit too messy and I am not sure if it is right.. How do I go about solving this? That is get a closed form out of it. The specific unbiased coin problem has a solution in terms of fibonacci numbers(which has a closed form solution).

-
I strongly suspect this is going to be a royal mess in the general, unbiased case. For example, in this answer I analyze a related problem that satisfies the same recurrence but has a different set of initial conditions. For the general case with $k=2$ the answer is already looking nasty. –  Mike Spivey Jan 18 '13 at 4:47
@MikeSpivey I see.. I understood as much I could, I think I will need to study a bit more to totally grasp the things you showed there. Thanks! –  Andariel Jan 18 '13 at 5:05
If a reference would be helpful, most of the techniques I use in that answer are discussed in Chapter 8 of Concrete Mathematics. –  Mike Spivey Jan 18 '13 at 5:09
I can't get a number, but I can find the generating function for the probabilities you want. Would that be helpful? Also there is a slick (and pretty elementary) way to get $E(X)$ where $X$ is the number of flips until you see $k$ heads in a row, from which you can get some estimates on the probability too. –  Mihai Nica Jan 18 '13 at 5:11
Ah awesome, I am routinely doing the problems from that book, so I guess I will learn about it soon.Thanks again. –  Andariel Jan 18 '13 at 5:13