In Rabin–Karp string search, a sliding window keeps a contiguous text segment the same length as the pattern and shifts it one character at a time. Instead of recalculating each window’s hash, subtract the character leaving and add the one entering. When hashes match, compare the characters to rule out a collision. section 4.4 section 4.1
Updating the hash
For the window ALI, the simple hash is 22. Shift to LIC by removing A’s value (1) and adding C’s value (3): 22 − 1 + 3 = 24. The next window’s hash is updated without summing all its characters again. section 4.1
Figure 4.3 A sliding window of size equal to the size of the pattern. The window slides by one character. The character A exits from the left, and the character C enters.
See the pattern-length window shift one character, with A leaving on the left as C enters on the right. section 4.1







