Skip to main content

Questions tagged [rolling-hash]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
53 views

Understanding Polynomial Rolling Hash Function by Modular Arithmetic

I was learning the Polynomial Hash function in python, the one used in Rabin Karp Algorithm This is the implementation I was taught: ...
reverseambition's user avatar
2 votes
1 answer
341 views

Understanding Rabin-Karp's rolling hash computation

Possibly related to this. Let $T$ be the text and $n$ be the length of the pattern. I understand that if substrings of $T$ are interpreted as base-$d$ numbers where $d$ is the alphabet's size, then ...
giofrida's user avatar
  • 183
1 vote
2 answers
196 views

How to use a worst case scenario in Rolling Hash: Rabin Karp Algorithm when the given string only contains the occurrences of "a and b?"

Issue: I am having a hard time figuring out how to use the worst case for Rolling Hash, especially if the occurrences are only "a and b" for the string. Not only that but it is a bit of a ...
Ralph Henry's user avatar
2 votes
2 answers
169 views

Rolling hash hacking

The hash value of a string $s$ is given by $$ h(s) = \sum^{|s|}_{i = 1} s_i \cdot p^{|s| - i} \mod m; \text{ $m$ is prime, $m < 10^{12}$}. $$ The string $s$, $p$, $m$ is given, $|s| \le 14$, ...
zdikov's user avatar
  • 21
1 vote
1 answer
474 views

finding all cyclic substrings of a string

I have been stuck on this problem for a while now; any help would be appreciated. Given a string S, find the number of distinct substrings which are composed of 2 or more consecutive strings. For ...
pblpbl's user avatar
  • 53
3 votes
3 answers
2k views

By what criteria is the base value selected in Rabin Karp algorithm?

In the Rabin Karp algorithm the rolling hash is calculated as follows: H1= c1*a^k-1 + c2*a^k-2+c3*a^k-3+…+ck*a^0 where a is a ...
Navjot Singh's user avatar
  • 1,215
1 vote
0 answers
3k views

Rolling Hash calculation with Horner's method

I understood how Horner's method reduces the complexity(number of operations) while evaluating a polynomial. I have a character array derived from a string ...
Arun Rahul's user avatar
2 votes
3 answers
2k views

How does Rabin fingerprint finds breakpoints (chunk boundary)?

I was reading up on chunking and found Rabin fingerprinting is also used to break files into chunks. After reading about this algorithm, I understood how rolling hash is computed using Rabin ...
user270386's user avatar
1 vote
2 answers
1k views

modular arithmetic in rolling hash algorithm

My question was around the rolling hash function in RobinKarp algorithm. It is intuitive for me to understand how to get from xi to xi+1 without the mod, however with the mod i am not sure how we ...
noi.m's user avatar
  • 135
0 votes
1 answer
206 views

Adding a character in the middle (rolling hash)

Is there a way to support adding characters in the middle and update the hash in O(1) ? All I have is the hash of ABBDE and I want to get the hash of ABBCDE.
lstdiraf's user avatar
2 votes
1 answer
80 views

Repeated fingerprinting after array updates

I've got a microprocessor and want to quickly identify the settings of my application (stored in some eeprom regions) via a fingerprint instead of having to dump the entire memory every time. So I ...
Bergi's user avatar
  • 608
3 votes
1 answer
946 views

pattern search with k-mismatch

I have used Rabin Karp Rolling Hash for searching a pattern $P$ in a text $T$. Now I am allowing $k$-mismatches, but not able to do a faster implementation. I tried modifying RK algorithm by ...
CPP_NEW's user avatar
  • 31
10 votes
1 answer
1k views

Does the Rabin-Karp really need me to care about applying a mod Q operation on the rolling hashes?

I have been reading about the Rabin Karp algorithm and I kept wondering what's the big deal with keeping our rolling hashes values bounded by a value Q? I'd thought that as our integer number ...
devoured elysium's user avatar
4 votes
1 answer
3k views

Finding hash of a substring $[i, j]$ in $O(1)$ using $O(|S|)$ pre computation

Given a string $S$ of length $n$ characters, is it possible to calculate the hash of its substring $[i, j]$ (from index $i$ to $j$, both inclusive) in $O(1)$ using some form of precomputation? Can we ...
Kyuubi's user avatar
  • 273
15 votes
2 answers
5k views

Why is the base used to compute hashes in Rabin–Karp always primes?

The Rabin–Karp string matching algorithm requires a hash function which can be computed quickly. A common choice is $$ h(x_0\ldots x_n) = \sum_{i=0}^n b^i x_i, $$ where $b$ is prime (all computations ...
Saurabh Jain's user avatar
7 votes
1 answer
3k views

Find longest common substring using a rolling hash

The longest common substring (LCS) of two input strings $s,t$ is a common substring (in both of them) of maximum length. We can relax the constraints to generalize the problem: find a common substring ...
mrk's user avatar
  • 3,718
1 vote
0 answers
1k views

Problem with Cormen's treatment of the Rabin-Karp algorithm

I am reading chapter 32 - String Matching from the book "Introduction to Algorithms" 3rd edition Cormen et al. The Rabin-Karp Algorithm is not clear to me despite heaving read it several times. ...
gpuguy's user avatar
  • 1,799