A classical probability question asks for the expected waiting time for flipping a coin (fair or not) until a series of consecutive k heads occur. Now instead of k heads, we can ask for the expected waiting time for a prescribed string such as HTHHTT (H for 'head' and T for 'tail'), and furthermore, the following more general setting: replacing coin flipping by taking a letter, one at a time, what is the expected waiting time until a prescribed string (a series of letters) is reached? Here we allow different probabilities for the occurrence of different letters. We give an exposition to this problem by offering an elementary algorithm and implementing it to compute the corresponding probability generating function: we show that there exists a universal program taking as inputs the choice of letters with given probabilities and the prescribed string, and as output, returning the probability generating function for the waiting time. The same method is applied to solve the problem of several competing strings, which asks for the probability (or more generally the probability generating function) of one of the given strings occurring before the remaining strings. In particular, this solves the problem of finding the expectation and variance for the waiting time random variable of the first problem.
scite is a Brooklyn-based organization that helps researchers better discover and understand research articles through Smart Citations–citations that display the context of the citation and describe whether the article provides supporting or contrasting evidence. scite is used by students and researchers from around the world and is funded in part by the National Science Foundation and the National Institute on Drug Abuse of the National Institutes of Health.