string,algorithm,matching,knuth-morris-pratt,rabin-karp

When you want to search for multiple patterns tipically the correct choice is to use Aho-Corasick which is somewhat a generalization of KMP. Now in your case you are only searching for 3 patterns so it may be the case that KMP is not that much slower(at most three times),...

To me it looks the same as in the theory before. The trick is that they do it in small steps (constructing the polynomial) Consider a very simple example of a string of length 3: We initialize ht = 0. The loop will first get position 0: ht = text[0]...

algorithm,string-matching,rabin-karp

One approach would be in three steps: 1) For each horizontal line, use the Rabin-Karp rolling hash to compute hash values covering each contiguous stretch of hash characters of length k along that line. 2) For each column, use the Rabin-Karp rolling hash down the column to take hash values...