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
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
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
A. Aho, J. Hoperoft, J. Ullman: The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974
G. Barth: Analyzing Algorithms by Markov Chains. Methods of Operations Research, Vol. 45, Athenaum Press, 1982, 405–418
R. Boyer, J. Moore: A Fast String Searching Algorithm. CACM 20 (1977), 262–272
L.J. Guibas, A.M. Odlyzko: String Overlaps, Pattern Matching and Nontransitive Games. Journal of Combinatorial Theory, Series A30 (1981), 183–208
E. Horowitz, S. Sahni: Fundamentals of Computer Algorithms. Computer Science Press, 1978
D. Knuth: The Art of Computer Programming, Vols. 1 and 3. Addison-Wesley, 1973
D. Knuth, J. Morris, V. Pratt: Fast Pattern Matching in Strings. SIAM Journal on Computing 6 (1977), 323–350
E. Reingold, J. Nievergelt, N. Deo: Combinatorial Algorithms. Prentice-Hall, 1977
R. Sedgewick: Algorithms. Addison-Wesley, 1983
J. Snell: Introduction to Probability Theory with Computing, Prentice-Hall, 1975
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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