Fast counting of 2D sub-matrices withing a large, dense 2D matrix?

前端 未结 4 1536
庸人自扰
庸人自扰 2020-12-16 06:29

What\'s a good algorithm for counting submatrices within a larger, dense matrix? If I had a single line of data, I could use a suffix tree, but I\'m not sure if generalizing

4条回答
  •  星月不相逢
    2020-12-16 06:54

    Algorithms and Theory of Computation Handbook suggests what is an N^2 * log(Alphabet Size) solution. Given a sub-matrix to search for, first of all de-dupe its rows. Now note that if you search the large matrix row by row at most one of the de-duped rows can appear at any position. Use Aho-Corasick to search this in time N^2 * log(Alphabet Size) and write down at each cell in the large matrix either null or an identifier for the matching row of the sub-matrix. Now use Aho-Corasick again to search down the columns of this matrix of row matches and signal a match where all the rows are present below each other.

提交回复
热议问题