Questions tagged [rabin-karp]

The Rabin-Karp string matching algorithm is a string matching algorithm that employs a rolling hash function to speed up the search.

Wiki

In computer science, the Rabin–Karp algorithm is a string searching algorithm. For a text of length n and p patterns of combined length m, its average and best case running time is O(n+m) in space O(p), but its worst-case time is O(nm).

Algorithm pseudocode

function RabinKarp(string s[1..n], string sub[1..m])
  hsub := hash(sub[1..m]);  hs := hash(s[1..m])        
  for i from 1 to n-m+1
    if hs = hsub
      if s[i..i+m-1] = sub
        return i
    hs := hash(s[i+1..i+m])
  return not found

Tag usage

The tag can be used for programming related problems in implementing Rabin-Karp algorithm in any programming language. Please avoid theoretical and conceptual questions on StackOverflow using the tag .

Read more

107 questions
-3
votes
2 answers

Rabin-Karp algorithm: Why is h=(h*d)%q

I understand the following in the Rabin-Karp algorithm h=d^m-1 but I fail to understand why we write for(i=0;i
poornima
  • 25
  • 1
  • 3
-3
votes
1 answer

Rabin Karp Algorithm in pascal

Can someone give me a source code for a function - Rabin Karp algorithm - in pascal (free pascal version)?
1 2 3 4 5 6 7
8