Algorithms and Data Structures · Senior · Question 21 of 75

What is the key idea of the Rabin-Karp string search?

Explanation

When the window slides by one character, the hash is updated by removing the old character and adding the new one. Only windows with a matching hash are compared character by character. It shines when searching for many patterns at once.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 21

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz