Overview
Naive String Search aligns the pattern with each text position and compares characters until a mismatch or full match.
Finds a pattern by checking every possible starting position.
Compact metadata for implementation and discovery.
Naive String Search aligns the pattern with each text position and compares characters until a mismatch or full match.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(nm)
Worst
O(nm)
Space
O(1)
match at i if pattern[j] == text[i + j] for every jChecks whether the pattern matches the text at one starting position.
Show a pattern sliding one character at a time over text.
Naive search is easiest to verify, but repeated partial matches can make it slow.
What each reference supports for this entry.
String algorithms reference covering Naive String Search recurrences, automata/indexing structures, or exact/approximate matching role.
Good next jumps from the relationship graph, ranked for useful discovery.
KMP improves on naive search by reusing prefix information.
Both search for patterns in text with different matching strategies.