diff --git a/Algorithms/String Matching/Rabin_karp.cpp b/Algorithms/String Matching/Rabin_karp.cpp new file mode 100644 index 0000000..3b9f57e --- /dev/null +++ b/Algorithms/String Matching/Rabin_karp.cpp @@ -0,0 +1,75 @@ +/*Rolling Hash +1) Calculate Hash for pattern +2) Calculate Hash for 1st window in text +3) Repeat the following : (until text ends) + a) If Hash(pat)==Hash(Text_Window) + then match characters one by one + b) Subtract leftmost (msb) from HASH(text_window) + c) Shift entire hash(text_window) by 1 unit to left + d) Add new character to window +*/ + +#include +#define ll long long int +using namespace std; + +ll createHashValue (string text, int len, ll prime) { + + ll result = 0; + for (int i=0; i