Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-vsgnj Total loading time: 0 Render date: 2024-07-23T07:24:45.987Z Has data issue: false hasContentIssue false

2 - String matching

Published online by Cambridge University Press:  18 December 2014

Gonzalo Navarro
Affiliation:
Universidad de Chile
Mathieu Raffinot
Affiliation:
Centre National de la Recherche Scientifique (CNRS), Paris
Get access

Summary

Basic concepts

The string matching problem is that of finding all the occurrences of a given pattern p = p1p2pm a large text T = t1t2tn, where both T and p are sequences of characters from a finite character set Σ. Given strings x, y, and z, we say that x is a prefix of xy, a suffix of yx, and a factor of yxz.

Many algorithms exist to solve this problem. The oldest and most famous are the Knuth-Morris-Pratt and the Boyer-Moore algorithms. These algorithms appeared in 1977. The first is worst-case linear in the size of the text. This O(n) complexity is a lower bound for the worst case of any string matching algorithm. The second is O(mn) in the worst case but is sublinear on average, that is, it may avoid reading some characters of the text. An O(nlog|Σ|m/m) lower bound on the average complexity has been proved in [Yao79].

Since 1977, many studies have been undertaken to find simpler algorithms, optimal average-case algorithms, algorithms that could also search extended patterns, constant space algorithms, and so on. There exists a large variety of research directions that have been tried, many of which lead to different string matching algorithms.

The aim of this chapter is not to present as many algorithms as possible, nor to give an exhaustive list of them. Instead, we will present the most efficient algorithms, which means the algorithms that for some pattern length and some alphabet size yield the best experimental results. Among those that have more or less the same efficiency, we will present the simplest.

The algorithms we present derive from three general search approaches, according to the way the text is searched. For all of them, a search window of the size of the pattern is slid from left to right along the text, and the pattern is searched for inside the window.

Type
Chapter
Information
Flexible Pattern Matching in Strings
Practical On-Line Search Algorithms for Texts and Biological Sequences
, pp. 15 - 40
Publisher: Cambridge University Press
Print publication year: 2002

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • String matching
  • Gonzalo Navarro, Universidad de Chile, Mathieu Raffinot, Centre National de la Recherche Scientifique (CNRS), Paris
  • Book: Flexible Pattern Matching in Strings
  • Online publication: 18 December 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781316135228.002
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • String matching
  • Gonzalo Navarro, Universidad de Chile, Mathieu Raffinot, Centre National de la Recherche Scientifique (CNRS), Paris
  • Book: Flexible Pattern Matching in Strings
  • Online publication: 18 December 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781316135228.002
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • String matching
  • Gonzalo Navarro, Universidad de Chile, Mathieu Raffinot, Centre National de la Recherche Scientifique (CNRS), Paris
  • Book: Flexible Pattern Matching in Strings
  • Online publication: 18 December 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781316135228.002
Available formats
×