Mental Model
We use a number to represent a string and slide over the text to find matches quickly by comparing these numbers instead of characters.
Analogy: Imagine checking if a small painting is inside a big mural by comparing the color codes of small sections instead of looking at every detail each time.
Text: T -> h -> i -> s -> -> i -> s -> -> a -> -> t -> e -> x -> t -> null Pattern: a -> -> t -> null Hash: pattern_hash = 123, current_text_hash = 456 Window slides over text characters
