Computing the Pattern Waiting Time: A Revisit of the Intuitive Approach

Author Kai Jin

Thumbnail PDF


  • Filesize: 460 kB
  • 12 pages

Document Identifiers

Author Details

Kai Jin

Cite AsGet BibTex

Kai Jin. Computing the Pattern Waiting Time: A Revisit of the Intuitive Approach. In 27th International Symposium on Algorithms and Computation (ISAAC 2016). Leibniz International Proceedings in Informatics (LIPIcs), Volume 64, pp. 39:1-39:12, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2016)


We revisit the waiting time of patterns in repeated independent experiments. We show that the most intuitive approach for computing the waiting time, which reduces it to computing the stopping time of a Markov chain, is optimum from the perspective of computational complexity. For the single pattern case, this approach requires us to solve a system of m linear equations, where m denotes the length of the pattern. We show that this system can be solved in O(m + n) time, where n denotes the number of possible outcomes of each single experiment. The main procedure only costs O(m) time, while a preprocessing rocedure costs O(m + n) time. For the multiple pattern case, our approach is as efficient as the one given by Li [Ann. Prob., 1980]. Our method has several advantages over other methods. First, it extends to compute the variance or even higher moment of the waiting time for the single pattern case. Second, it is more intuitive and does not entail tedious mathematics and heavy probability theory. Our main result (Theorem 2) might be of independent interest to the theory of linear equations.
  • Pattern Occurrence
  • Waiting Time
  • Penney’s Game
  • Markov Chain


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Anonymous. Penney’s game. Technical report, Wikipedia, 2016. URL:
  2. J. A. D. Aston and D. E. K. Martin. Waiting time distributions of competing patterns in higher-order markovian sequences. Journal of Applied Probability, 42(4):977-988, 2005. Google Scholar
  3. N. Balakrishnan and M. V. Koutras. Runs and Scans with Applications. Wiley, 2002. Google Scholar
  4. S. Breen, M. S. Waterman, and N. Zhang. Renewal theory for several patterns. Journal of Applied Probability, 22(1):228-234, 1985. Google Scholar
  5. O. Chrysaphinou and S. Papastavridis. The occurrence of sequence patterns in repeated dependent experiments. Theory of Probability &Its Applications, 35(1):145-152, 1991. URL:
  6. J. A. Csirik. Optimal strategy for the first player in the penney ante game. Combinatorics, Probability and Computing, 1:311-321, 1992. URL:
  7. W. Feller. An Introduction to Probability Theory and its Applications, volume 1. Wiley, 3 edition, 1968. Google Scholar
  8. J. C. Fu and W. Y. W. Lou. Distribution Theory of Runs and Patterns and Its Applications. World Scientific Publishing, 2003. Google Scholar
  9. I. Fudos, E. Pitoura, and W. Szpankowski. On pattern occurrences in a random text. Information Processing Letters, 57(6):307-312, 1996. Google Scholar
  10. M. Gardner. On the paradoxical situations that arise from nontransitive relations. Scientific American, 231(4), 1974. Google Scholar
  11. R. L. Graham, D. E. Knuth, and O. Patashnik. Concrete Mathematics: A Foundation for Computer Science. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 2nd edition, 1994. Google Scholar
  12. L. J. Guibas and A. M. Odlyzko. String overlaps, pattern matching, and nontransitive games. Journal of Combinatorial Theory, Series A, 30(2):183-208, 1981. URL:
  13. D. E. Knuth, Jr. J. H. Morris, and V. R. Pratt. Fast pattern matching in strings. SIAM Journal on Computing, 6(2):323-350, 1977. URL:
  14. S. R. Li. A martingale approach to the study of occurrence of sequence patterns in repeated experiments. The Annals of Probability, 8(6):1171-1176, 1980. Google Scholar
  15. M. E. Lladser, M. D. Betterton, and R. Knight. Multiple pattern matching: a markov chain approach. Journal of Mathematical Biology, 56(1):51-92, 2007. URL:
  16. M. Lothaire. Applied Combinatorics on Words. Cambridge University Press, 2005. Google Scholar
  17. W. Penney. Problem 95: Penney-ante. Journal of Recreational Mathematics, page 241, 1969. Google Scholar
  18. V. Pozdnyakov. On occurrence of patterns in markov chains: Method of gambling teams. Statistics &Probability Letters, 78(16):2762-2767, 2008. URL:
  19. V. Pozdnyakov and M. Kulldorff. Waiting times for patterns and a method of gambling teams. The American Mathematical Monthly, 113(2):134-143, 2006. Google Scholar
  20. M. Régnier. A unified approach to word occurrence probabilities. Discrete Applied Mathematics, 104:259-280, 2000. Google Scholar
  21. M. Régnier and W. Szpankowski. On pattern frequency occurrences in a markovian sequence. Algorithmica, 22(4):631-649, 1998. URL:
  22. G. Reinert, S. Schbath, and M. S. Waterman. Probabilistic and statistical properties of words: An overview. Journal of Computational Biology, 7(2):1-46, 2000. Google Scholar
  23. A. D. Solov'ev. A combinatorial identity and its application to the problem concerning the first occurrence of a rare event. Theory of Probability &Its Applications, 11(2):276-282, 1966. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail