An algorithm is presented which finds all occurrences of one given string within another, in running time proportional to the sum of the lengths of the strings. The constant of proportionality is low enough to make this algorithm of practical use, and the procedure can also be extended to deal with some more general pattern-matching problems. A theoretical application of the algorithm shows that the set of concatenations of even palindromes, i.e., the language $\{\alpha \alpha ^R\}^*$, can be recognized in linear time. Other algorithms which run even faster on the average are also considered.


  1. pattern
  2. string
  3. text-editing
  4. pattern-matching
  5. trie memory
  6. searching
  7. period of a string
  8. palindrome
  9. optimum algorithm
  10. Fibonacci string
  11. regular expression

Get full access to this article

View all available purchase options and get full access to this article.


Alfred V. Aho, John E. Hopcroft, Jeffrey D. Ullman, The design and analysis of computer algorithms, Addison-Wesley Publishing Co., Reading, Mass.-London-Amsterdam, 1975x+470
Alfred V. Aho, Margaret J. Corasick, Efficient string matching: an aid to bibliographic search, Comm. ACM, 18 (1975), 333–340
M. Beeler, R. W. Gosper, R. Schroeppel, HAKMEM, Memo No. 239, M.I.T. Artificial Intelligence Laboratory, Cambridge, Mass., 1972
S. Robert, J. Strother Moore, A fast string searching algorithm, 1975, manuscript dated December 29, Stanford Research Institute, Menlo Park, Calif., and Xerox Palo Alto Research Center, Palo Alto, Calif.
Stephen A. Cook, Linear time simulation of deterministic two-way pushdown automataInformation processing 71 (Proc. IFIP Congress, Ljubljana, 1971), Vol. 1: Foundations and systems, North-Holland, Amsterdam, 1972, 75–80
Pascal Diethelm, Peter Roizen, An efficient linear search for a pattern in a string, 1972, unpublished manuscript dated April, World Health Organization, Geneva, Switzerland
N. J. Fine, H. S. Wilf, Uniqueness theorems for periodic functions, Proc. Amer. Math. Soc., 16 (1965), 109–114
Michael J. Fischer, Michael S. Paterson, String-matching and other productsComplexity of computation (Proc. SIAM-AMS Appl. Math. Sympos., New York, 1973), Amer. Math. Soc., Providence, R. I., 1974, 113–125. SIAM-AMS Proc., Vol. VII
Zvi Galil, On converting on-line algorithms into real-time and on real-time algorithms for string-matching and palindrome recognition, SIGACT News, 7 (1975), 26–30
E. N. Gilbert, Synchronization of binary messages, IRE Trans., IT-6 (1960), 470–477, Information Theory
Sheila A. Greibach, The hardest context-free language, SIAM J. Comput., 2 (1973), 304–310
Malcolm C. Harrison, Implementation of the substring test by hashing, Comm. ACM, 14 (1971), 777–779
Richard M. Karp, Raymond E. Miller, Arnold L. Rosenberg, Rapid identification of repeated patterns in strings, trees, and arrays, ACM Symposium on Theory of Computing, Vol. 4, Association for Computing Machinery, New York, 1972, 125–136
Donald E. Knuth, The art of computer programming. Vol. 1: Fundamental algorithms, Second printing, Addison-Wesley Publishing Co., Reading, Mass.-London-Don Mills, Ont, 1969xxi+634
Donald E. Knuth, The art of computer programming. Volume 3, Addison-Wesley Publishing Co., Reading, Mass.-London-Don Mills, Ont., 1973xi+722 pp. (1 foldout)
Donald E. Knuth, Sequences with precisely $k+1$k-blocks, Solution to problem E2307, Amer. Math. Monthly, 79 (1972), 773–774
Donald E. Knuth, On the translation of languages from left to right, Information and Control, 8 (1965), 607–639
Donald E. Knuth, Structured programming with go to statements, Computing Surveys, 6 (1974), 261–301
Donald E. Knuth, James H. Morris, Jr., Vaughan R. Pratt, Fast pattern matching in strings, Tech. Rep. CS440, Computer Science Department, Stanford Univ., Stanford, Calif., 1974
R. C. Lyndon, M. P. Schützenberger, The equation $a\sp{M}=b\sp{N}c\sp{P}$ in a free group, Michigan Math. J., 9 (1962), 289–298
Glenn Manacher, A new linear-time on-line algorithm for finding the smallest initial palindrome of a string, J. Assoc. Comput. Mach., 22 (1975), 346–351
A. Markoff, Sur une question de Jean Bernoulli, Math. Ann., 19 (1881), 27–36
J. H. Morris, Jr., Vaughan R. Pratt, A linear pattern -matching algorithm, Tech. Rep. 40, Univ. of California, Berkeley, 1970
A. O. Slisenko, Identification of the symmetry predicate by means of multihead Turing machines with input, Trudy Mat. Inst. Steklov., 129 (1973), 30–202, 267. (errata insert)
Ken Thompson, Regular expression search algorithm, Comm. ACM, 11 (1968), 419–422
B. A. Venkov, Elementary number theory, Translated from the Russian and edited by Helen Alderson, Wolters-Noordhoff Publishing, Groningen, 1970ix+249
Peter Weiner, Linear pattern matching algorithms, 14th Annual IEEE Symposium on Switching and Automata Theory (Univ. Iowa, Iowa City, Iowa, 1973), IEEE Comput. Soc., Northridge, Calif., 1973, 1–11

Information & Authors


Published In

cover image SIAM Journal on Computing
SIAM Journal on Computing
Pages: 323 - 350
ISSN (online): 1095-7111


Submitted: 29 August 1974
Published online: 13 July 2006


  1. pattern
  2. string
  3. text-editing
  4. pattern-matching
  5. trie memory
  6. searching
  7. period of a string
  8. palindrome
  9. optimum algorithm
  10. Fibonacci string
  11. regular expression



Metrics & Citations



If you have the appropriate software installed, you can download article citation data to the citation manager of your choice. Simply select your manager software from the list below and click Download.

Cited By