English

Fast Searching in Packed Strings

Data Structures and Algorithms 2010-09-08 v2

Abstract

Given strings PP and QQ the (exact) string matching problem is to find all positions of substrings in QQ matching PP. The classical Knuth-Morris-Pratt algorithm [SIAM J. Comput., 1977] solves the string matching problem in linear time which is optimal if we can only read one character at the time. However, most strings are stored in a computer in a packed representation with several characters in a single word, giving us the opportunity to read multiple characters simultaneously. In this paper we study the worst-case complexity of string matching on strings given in packed representation. Let mnm \leq n be the lengths PP and QQ, respectively, and let σ\sigma denote the size of the alphabet. On a standard unit-cost word-RAM with logarithmic word size we present an algorithm using time O(nlogσn+m+\occ). O\left(\frac{n}{\log_\sigma n} + m + \occ\right). Here \occ\occ is the number of occurrences of PP in QQ. For m=o(n)m = o(n) this improves the O(n)O(n) bound of the Knuth-Morris-Pratt algorithm. Furthermore, if m=O(n/logσn)m = O(n/\log_\sigma n) our algorithm is optimal since any algorithm must spend at least Ω((n+m)logσlogn+\occ)=Ω(nlogσn+\occ)\Omega(\frac{(n+m)\log \sigma}{\log n} + \occ) = \Omega(\frac{n}{\log_\sigma n} + \occ) time to read the input and report all occurrences. The result is obtained by a novel automaton construction based on the Knuth-Morris-Pratt algorithm combined with a new compact representation of subautomata allowing an optimal tabulation-based simulation.

Keywords

Cite

@article{arxiv.0907.3135,
  title  = {Fast Searching in Packed Strings},
  author = {Philip Bille},
  journal= {arXiv preprint arXiv:0907.3135},
  year   = {2010}
}

Comments

To appear in Journal of Discrete Algorithms. Special Issue on CPM 2009

R2 v1 2026-06-21T13:26:16.988Z