The occurrence of sequence patterns in repeated experiments and hitting times in a Markov chain

A martingale argument is used to derive the generating function of the number of i.i.d. experiments it takes to observe a given string of outcomes for the first time. Then, a more general problem can be studied: How many trials does it take to observe a member of a finite set of strings for the first time? It is shown how the answer can be obtained within the framework of hitting times in a Markov chain. For these, a result of independent interest is derived.