Complete the code to initialize the prime number used for hashing.
final int prime = [1];The prime number 101 is commonly used in Rabin Karp for hashing to reduce collisions.
Complete the code to compute the initial hash value for the pattern string.
for (int i = 0; i < pattern.length(); i++) { patternHash = (patternHash * prime + pattern.charAt(i)) % [1]; }
The modulus value is used to keep the hash value within integer limits and avoid overflow.
Fix the error in the rolling hash update inside the loop.
textHash = (prime * (textHash - text.charAt(i) * [1]) + text.charAt(i + pattern.length())) % modulus;The variable 'power' holds prime^(pattern.length()-1) used to remove the leading character's contribution from the hash.
Fill both blanks to correctly check for a hash match and then verify the actual substring.
if (patternHash == textHash && text.substring(i, i + [1]).equals([2])) { result.add(i); }
We compare substring length equal to pattern length and check if substring equals the pattern.
Fill all three blanks to complete the Rabin Karp search method header and return statement.
public static List<Integer> [1](String text, String [2]) { List<Integer> result = new ArrayList<>(); // ... algorithm implementation ... return [3]; }
The method is named rabinKarpSearch, takes pattern as parameter, and returns the result list.
