Dynamic and Approximate Pattern Matching in 2D

Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9954)


We consider dynamic and online variants of 2D pattern matching between an \(m \times m\) pattern and an \(n \times n\) text. All the algorithms we give are randomised and give correct outputs with at least constant probability.

  • For dynamic 2D exact matching where updates change individual symbols in the text, we show updates can be performed in \( \mathcal {O}(\log ^2 n)\) time and queries in \(\mathcal {O}(\log ^2 m)\) time.

  • We then consider a model where an update is a new 2D pattern and a query is a location in the text. For this setting we show that Hamming distance queries can be answered in \(\mathcal {O}(\log m + H)\) time, where H is the relevant Hamming distance.

  • Extending this work to allow approximation, we give an efficient algorithm which returns a \((1+\varepsilon )\) approximation of the Hamming distance at a given location in \(\mathcal {O}(\varepsilon ^{-2} \log ^2 m \log {\log n})\) time.

Finally, we consider a different setting inspired by previous work on locality sensitive hashing (LSH). Given a threshold k and after building the 2D text index and receiving a 2D query pattern, we must output a location where the Hamming distance is at most \((1+\varepsilon )k\) as long as there exists a location where the Hamming distance is at most k.

  • For our LSH inspired 2D indexing problem, the text can be preprocessed in \(\mathcal {O}(n^{2(4/3+1/(1+\varepsilon ))} \log ^3 n)\) time into a data structure of size \(\mathcal {O}(n^{2(1+1/(1+\varepsilon ))})\) with query time \(\mathcal {O}(n^{2(1/(1+\varepsilon ))} m^2)\).


Hash Function Pattern Match Suffix Tree Text Index Locality Sensitive Hash 
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.


  1. 1.
    Alon, N., Matias, Y., Szegedy, M.: The space complexity of approximating the frequency moments. In: STOC 1996, pp. 20–29. ACM (1996)Google Scholar
  2. 2.
    Amir, A., Benson, G.: Efficient two-dimensional compressed matching. In: Data Compression Conference, DCC 1992, pp. 279–288. IEEE (1992)Google Scholar
  3. 3.
    Amir, A., Benson, G.: Two-dimensional periodicity in rectangular arrays. SIAM J. Comp. 27(1), 90–106 (1998)MathSciNetCrossRefzbMATHGoogle Scholar
  4. 4.
    Amir, A., Benson, G., Farach, M.: Optimal two-dimensional compressed matching. J. Algorithms 24(2), 354–379 (1997)MathSciNetCrossRefzbMATHGoogle Scholar
  5. 5.
    Amir, A., Butman, A., Crochemore, M., Landau, G.M., Schaps, M.: Two-dimensional pattern matching with rotations. Theor. Comput. Sci. 314(1), 173–187 (2004)MathSciNetCrossRefzbMATHGoogle Scholar
  6. 6.
    Amir, A., Farach, M.: Efficient 2-dimensional approximate matching of non-rectangular figures. In: SODA, pp. 212–223 (1991)Google Scholar
  7. 7.
    Amir, A., Farach, M.: Efficient 2-dimensional approximate matching of half-rectangular figures. Inf. Comput. 118(1), 1–11 (1995)MathSciNetCrossRefzbMATHGoogle Scholar
  8. 8.
    Amir, A., Landau, G.M., Lewenstein, M., Sokol, D.: Dynamic text and static pattern matching. ACM Trans. Algorithms (TALG), 3(2) (2007)Google Scholar
  9. 9.
    Amir, A., Landau, G.M., Sokol, D.: Inplace run-length 2D compressed search. Theor. Comput. Sci. 290(3), 1361–1383 (2003)MathSciNetCrossRefzbMATHGoogle Scholar
  10. 10.
    Andoni, A., Indyk, P.: Efficient algorithms for substring near neighbor problem. In: SODA 2006, pp. 1203–1212 (2006)Google Scholar
  11. 11.
    Baker, T.P.: A technique for extending rapid exact-match string matching to arrays of more than one dimension. SIAM J. Comp. 7(4), 533–541 (1978)MathSciNetCrossRefzbMATHGoogle Scholar
  12. 12.
    Bird, R.S.: Two dimensional pattern matching. IPL 6(5), 168–170 (1977)CrossRefGoogle Scholar
  13. 13.
    Cole, R., Hariharan, R.: Dynamic LCA queries on trees. SIAM J. Comput. 34(4), 894–923 (2005)MathSciNetCrossRefzbMATHGoogle Scholar
  14. 14.
    Fredriksson, K., Navarro, G., Ukkonen, E.: Optimal exact and fast approximate two dimensional pattern matching allowing rotations. In: Apostolico, A., Takeda, M. (eds.) CPM 2002. LNCS, vol. 2373, pp. 235–248. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  15. 15.
    Galil, Z., Park, K.: Truly alphabet-independent two-dimensional pattern matching. In: FOCS 1992, pp. 247–256 (1992)Google Scholar
  16. 16.
    Giancarlo, R.: A generalization of the suffix tree to square matrices, with applications. SIAM J. Comp. 24(3), 520–562 (1995)MathSciNetCrossRefzbMATHGoogle Scholar
  17. 17.
    Gusfield, D.: Algorithms on Strings, Trees and Sequences. Computer Science and Computational Biology. Cambridge University Press, Cambridge (1997)CrossRefzbMATHGoogle Scholar
  18. 18.
    Karp, R.M., Rabin, M.O.: Efficient randomized pattern-matching algorithms. IBM J. Res. Dev. 31(2), 249–260 (1987)MathSciNetCrossRefzbMATHGoogle Scholar

Copyright information

© Springer International Publishing AG 2016

Authors and Affiliations

  1. 1.Department of Computer ScienceUniversity of BristolBristolUK
  2. 2.Technical University of Denmark, DTU ComputeKongens LyngbyDenmark

Personalised recommendations