AlgoPlus//strings / naive-string
Read the theory

Naïve String Matching

Align the pattern at every position and compare character by character.

Shift
Comparisons
Matches
Text
Pattern
Legend
Comparing
Match
Mismatch
AI Tutor Workspace
In a nutshell
Naïve string matching looks for a pattern inside a longer text by lining the pattern up at the first position and comparing character by character. On any mismatch it shifts the pattern one place right and starts over from the beginning. It needs no setup, but because each shift re-checks characters it may have already compared, it can do up to (text length × pattern length) comparisons.
Ready
Press play to begin the cinematic walkthrough.
Try the pattern at every starting position and compare straight through. Dead simple, but it keeps re-checking characters it already looked at.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Naïve String Matching.