Nu aveti permisiuni pentru a descarca fisierul grader_test3.ok
Diferente pentru blog/rolling-hash intre reviziile #11 si #12
Nu exista diferente intre titluri.
Diferente intre continut:
== code(c) | an = 1
rolling_hash = 0;
rolling_hash = 0
for i in range(0, n):
rolling_hash = (rolling_hash * a + S[i]) % MOD
an = (an * a) % MOD
h2. Longest common substring
bq. Given threestrings, compute their longest common substring.
bq. Given two strings A and B, compute their longest common substring.
Wecan find a common subsequence offixedlengthinlineartimeusingthe rolling hash technique.Basicallywe hash allfixedlength subseqences ofthethree stringsandcheck if theintersection ofthe threerespectivehashsets isnot empty.Nowto findthelargestlengthwecan useabinary searchalgorithm.
Let's solve a simpler problem: Given two strings A and B, and a number X find if they have a common sequence of length X. We use the rolling hash technique to find the hash codes for all X length substrings of A and B. Then we check if there is any common hash code between the two sets, this means A and B share a sequence of length X. We then use binary search to find the largest X.
The complexity of this algorithm is O(n log n). h2. rsync
