encyclopegia.org

Two-dimensional pattern matching

In computer science, two-dimensional pattern matching is the problem of locating occurrences of a two-dimensional matrix of characters ("the pattern") in a bigger two-dimensional matrix ("the picture", or, in analogy with string searching, "the text").[src]

In computer science, two-dimensional pattern matching is the problem of locating occurrences of a two-dimensional matrix of characters ("the pattern") in a bigger two-dimensional matrix ("the picture", or, in analogy with string searching, "the text").[src] ==The naïve solution== Assume given a pattern P[m\times m] and a text T[n\times n] , where m\le n .[src] The simplest approach is to compare P against every sub-array of size m\times m in T.[src] This algorithm has a worst-case time of \Theta((n-m+1)^2m^2) .[src] It is usually assume that m\le n/2 , whence this can be written as \Theta(n^2m^2) .[src] ==An automaton-based solution== We shall illustrate a more efficient solution (due essentially to ) by means of an example.[src] Suppose we have the following pattern and text abaab aba baaab P = bab T = abaab aba babab ababa We first construct a Aho-Corasick automaton to search a linear text for occurrences of the columns of P.[src] As a biproduct we obtain an identifier for every column, so that two identical columns get the same identifier: in our example, say the first (and third) columns are idntified by 0, and the middle column by 1.[src] Next, we run the automaton on the columns of T, obtaining (in linear time) an indication whenever one of the columns of P appears in T: in our example this will be a 3×5 matrix C as follow (a "-" marks an absence of a match): abaab aba baaab P = bab T = abaaa C = 01--- aba babab 10--1 ababa 010-0 We now use the Knuth-Morris-Pratt Algorithm to search the rows of C for a pattern identical to P, i.e., 010.[src] When we find one, we have identified an occurrence of P in T.[src] Note that it is not necessary to keep all of C, or all of T, in memory; T can be read row by row, and from C one only needs to keep one row in memory---along with a row of states of the Aho-Corasick and the KMP automata.[src] The running time of this algorithm is O(n^2) if one ignores the dependence on the size of the alphabet, which exists in the Aho-Corasick algorithm.[src] Taking this into account, the complexity is O(n^2\log k) where k is the size of the alphabet.[src] ==More efficient solutions== The dependence on the size of the alphabet was removed by an O(n^2) algorithm of Galil and Park.[src] ==See also== string searching algorithm ==Footnotes== ==References==[src]

16 sentences · 16 cited inline · 0 references stored

References

No reference rows published for this article.

Cite this article

MLA

"Two-dimensional pattern matching." encyclopegia.org, 2026, https://encyclopegia.org/wiki/two-dimensional-pattern-matching. Accessed 27 November 2026.

Chicago

"Two-dimensional pattern matching." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/two-dimensional-pattern-matching.

APA

encyclopegia.org. (2026). Two-dimensional pattern matching. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/two-dimensional-pattern-matching

Accessed November 27, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

bridge pattern

stub · references available

EFL League Two

stub · references available

The Two Noble Kinsmen

stub · references available

Epic Mickey 2: The Power of Two

stub · references available

proactor pattern

stub · references available

two-stage-to-orbit

stub · references available

Teresa Cristina of the Two Sicilies

stub · references available

two-dimensional space

stub · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1349116048 · 0.5 · snapshot enwiki-001349116048

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools
  • Careers — open roles: frontier engineers and sales partners

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.