Knuth-Morris-Pratt algorithm: An analysis

  • Mireille Regnier
Part of the Lecture Notes in Computer Science book series (LNCS, volume 379)


This paper deals with an average analysis of the Knuth-Morris-Pratt algorithm. Searching all occurrences of a given pattern p in a text of length n implies cp.n text-pattern comparisons. Averaging over all patterns yields a cost c.n. The constant of linearity c is derived. In particular, when the cardinality q of the alphabet is large, it is proven that c ∼ 1+1/q. An algebraic scheme is used, based on combinatorics on words and generating functions.


Markov Chain Algebraic Approach Naive Algorithm Left Factor String Match Algorithm 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [BA85]
    G. Barth ”An Analytical Comparison of Two String Matching Algorithms” in Information Processing Letters, 30 (1985) 249–256.Google Scholar
  2. [BA88]
    R. Baeza-Yates ”Analysis of String-Matching Algorithms” Waterloo Univ. Research ReportGoogle Scholar
  3. [CP88]
    M. Crochemore and D. Perrin ”Pattern Matching in Strings” in LITP (Paris) Research Report 88-5.Google Scholar
  4. [FL84]
    Ph. Flajolet”Mathematical Methods in the Analysis of Algorithms and Data Structures”, Lecture Notes for A Graduate Course on Computation Theory, Udine(Italy) 225–304(1984).Google Scholar
  5. [FL85]
    Ph. Flajolet ”Elements of a Theory of Combinatorial Structures” in Proc. FCT Conf., Lecture Notes in Computer Science, (1985) 112–127.Google Scholar
  6. [GJ83]
    I. Goulden and D. Jackson”Combinatorial Enumerations”, Wiley, New York, (1983).Google Scholar
  7. [GO81]
    L.J. Guibas and A.M. Odlyzko ”String overlaps, pattern matching, and nontransitive games” in J. Comb. Theory (A), 30 (1981) 183–208.Google Scholar
  8. [KMP77]
    D.E. Knuth, J.H. Morris and V.R. Pratt ”Fast Pattern Matching in Strings” in SIAM J. Comput.6, 2 (1977) 323–350.Google Scholar
  9. [LO82]
    Lothaire”Combinatorics on Words”, Addison-Wesley, Reading,Mass., (1982).Google Scholar
  10. [OD85]
    A.M. Odlyzko”Periodicities in Strings” in Combinatorial Algorithms on Words, Springer NATO ASI SEr. F12, (1985) 241–254.Google Scholar
  11. [RE88]
    M. Régnier”Enumeration of Sided Words” INRIA Research Report 956Google Scholar
  12. [RE89]
    M. Régnier”Knuth-Morris-Pratt algorithm: an analysis” INRIA Research Report 966Google Scholar
  13. [SE83]
    R. Sedgewick”Algorithms” Addison-Wesley, Reading, Mass., (1983).Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1989

Authors and Affiliations

  • Mireille Regnier
    • 1
  1. 1.INRIA-RocquencourtLe ChesnayFrance

Personalised recommendations