Two-dimensional pattern matching in linear time and small space

Extended abstract
  • Maxime Crochemore
  • Leszek Gasieniec
  • Wojciech Rytter
  • Wojciech Plandowski
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 900)


We present the first known (alphabet independent) algorithm for two-dimensional pattern matching which works in linear time and small space simultaneously. The searching phase of our algorithm works in O(1) space and is followed by pattern preprocessing performed in O(logm) space. Up to now there was not known even any efficient sublinear space algorithm for this problem. The main tools in our algorithm are several 2-dimensional variations of deterministic sampling, originally used in parallel pattern matching: small, frame and wide samples. Another novel idea used in our algorithm is the technique of zooming sequences: the sequences of nonperiodic decreasing parts of the pattern (samples) of similar regular shapes. Their regularity allows to encode the zooming sequences in small memory (logarithmic number of bits) while nonperiodicity allows to make shifts (kill positions as candidates for a match) in a way amortizing the work. The preprocessing phase is recursive, its structure is similar to the linear time algorithm for the selection problem. The stack of the recursion consists of logarithmic number of integers. Our algorithm is rather complicated, but all known alphabet-independent linear time algorithms (even with unrestricted space) for 2d-matching are quite complicated, too.


Linear Time Frame Sample Pattern Match Total Size String Match 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    A. Amir and G. Benson, Two dimensional periodicity and its applications, Proc. 3rd ACM-SIAM SODA'92, p. 440–452.Google Scholar
  2. 2.
    A. Amir, G. Benson and M. Farach, Alphabet independent two dimensional matching, Proc. 24th ACM STOC'92, p. 59–68.Google Scholar
  3. 3.
    A. Amir, G. Benson and M. Farach, Optimal parallel two dimensional pattern matching, Proc. 5th ACM SPAA'93, p. 79–85.Google Scholar
  4. 4.
    T. J. Baker, A technique for extending rapid exact-match string matching to arrays of more than one dimension, SIAM J. Comp. 7 (1978), p. 533–541.Google Scholar
  5. 5.
    R. S. Bird, Two dimensional pattern matching, Inf. Proc. Letters 6, (1977) p. 168–170.Google Scholar
  6. 6.
    R. Cole, M. Crochemore, Z. Galil, L. Gasieniec, R. Hariharan, S. Muthukrishnan, K. Park and W. Rytter, Optimally fast parallel algorithms for preprocessing and pattern matching in one and two dimensions, Proc. 34th IEEE FOCS'93, p. 248–258.Google Scholar
  7. 7.
    M. Crochemore, String matching for ordered alphabets, TCS 92 (1992), p. 225–251.Google Scholar
  8. 8.
    M. Crochemore and D. Perrin, Two-way string matching, JACM 38:3 (1991), p. 651–675.Google Scholar
  9. 9.
    M. Crochemore, L. Gasieniec and W. Rytter, Two-dimensional pattern matching by sampling, IPL 46 (1993), p. 159–162.Google Scholar
  10. 10.
    M. Crochemore and W. Rytter, A version of Galil-Park two-dimensional matching, Report IGM 94-05, Universite Marne la Valle (1994).Google Scholar
  11. 11.
    Z. Galil and K. Park, Truly alphabet independent two dimensional matching, Proc. 33th IEEE FOCS'92, (1992) p. 247–256.Google Scholar
  12. 12.
    Z. Galil and J. Seiferas, Time-space optimal string matching, J. Comp. Syst. Sc. 26 (1983), p. 280–294.Google Scholar
  13. 13.
    L. Gasieniec, W. Plandowski and W. Rytter, The zooming method: a recursive approach to time-space efficient string-matching, TCS, to appear.Google Scholar
  14. 14.
    U. Vishkin, Deterministic sampling — a new technique for fast pattern matching, SIAM J. Comput. 20 (1991), p. 22–40.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1995

Authors and Affiliations

  • Maxime Crochemore
    • 1
  • Leszek Gasieniec
    • 2
  • Wojciech Rytter
    • 2
  • Wojciech Plandowski
    • 2
  1. 1.Institut Gaspard MongeUniversité de Marne la ValléeNoisy le Grand
  2. 2.Instytut InformatkiUniwersytet WarszawskiWarszawa

Personalised recommendations