I tried to solve the two-dimensional search problem using a combination of Aho-Corasick and one-dimensional KMP, however I still need something faster.
To develop, I have a character matrix A of size n1 * n2, and I want to find all occurrences of a smaller matrix B of size m1 * m2, and I want it to be in O (n1 * n2 + m1 * m2), if possible .
For instance:
A = abcbcb bcacac dababa qasdqa
and
B = bcb cac aba
the algorithm should return the indices, say, the upper left corner of the match, which in this case should return (0,1) and (0,3). note that entries may overlap.
source share