Skip to main content

Relating the Average-Case Costs of the Brute-Force and Knuth-Morris-Pratt String Matching Algorithm

  • Conference paper
  • 343 Accesses

Part of the book series: NATO ASI Series ((NATO ASI F,volume 12))

Abstract

Among the algorithms which are able to check in 0(n+m) steps, if a string PATTERN = p1p2...pm occurs in a string TEXT = t1t2...tn, the one developed by Knuth, Morris and Pratt (KMP, for short) plays kind of a fundamental role. Its linear worst-case time complexity contrasts sharply with the 0(n.m) upper bound for the overhead of the brute-force strategy which naively probes each position i, for 1≤i≤n−m+1, in TEXT for a complete match

$$ {{p}_{1}}{{p}_{2}}...{{p}_{m}}={{t}_{i}}{{t}_{i+1}}...{{t}_{i+m-1}} $$

However, the average-case performance of the KMP algorithm has been suspected not to be drastically better than that of the naive method [9]:

“The Knuth-Morris-Pratt algorithm is not likely to be significantly faster than the brute-force method in most actual applications, ...”

The main objective of this paper is to elaborate on this observation and to present a detailed and accurate average-case analysis of both the brute-force and the KMP algorithm. The analysis exploits results from Markov chain theory. This approach is believed to be practically sound, since string matching can be modeled conveniently by finite-state devices.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. A. Aho, J. Hoperoft, J. Ullman: The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974

    Google Scholar 

  2. G. Barth: Analyzing Algorithms by Markov Chains. Methods of Operations Research, Vol. 45, Athenaum Press, 1982, 405–418

    Google Scholar 

  3. R. Boyer, J. Moore: A Fast String Searching Algorithm. CACM 20 (1977), 262–272

    Google Scholar 

  4. L.J. Guibas, A.M. Odlyzko: String Overlaps, Pattern Matching and Nontransitive Games. Journal of Combinatorial Theory, Series A30 (1981), 183–208

    MathSciNet  MATH  Google Scholar 

  5. E. Horowitz, S. Sahni: Fundamentals of Computer Algorithms. Computer Science Press, 1978

    Google Scholar 

  6. D. Knuth: The Art of Computer Programming, Vols. 1 and 3. Addison-Wesley, 1973

    Google Scholar 

  7. D. Knuth, J. Morris, V. Pratt: Fast Pattern Matching in Strings. SIAM Journal on Computing 6 (1977), 323–350

    Article  MathSciNet  MATH  Google Scholar 

  8. E. Reingold, J. Nievergelt, N. Deo: Combinatorial Algorithms. Prentice-Hall, 1977

    Google Scholar 

  9. R. Sedgewick: Algorithms. Addison-Wesley, 1983

    Google Scholar 

  10. J. Snell: Introduction to Probability Theory with Computing, Prentice-Hall, 1975

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 1985 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Barth, G. (1985). Relating the Average-Case Costs of the Brute-Force and Knuth-Morris-Pratt String Matching Algorithm. In: Apostolico, A., Galil, Z. (eds) Combinatorial Algorithms on Words. NATO ASI Series, vol 12. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-82456-2_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-82456-2_4

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-82458-6

  • Online ISBN: 978-3-642-82456-2

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics