naive string matching
Imagine sliding a small stencil of the word you are hunting for across the page, one letter at a time, and at each stop checking whether the letters underneath the stencil spell your word. That is naive string matching in a nutshell: try every possible alignment of the pattern against the text and test each one directly. It is the first thing anyone would invent, and it always works — it is just not always fast.
Concretely, for each shift s from 0 up to n-m, line the pattern P up so it starts at text position s, then compare P[0] with T[s], P[1] with T[s+1], and so on. If all m characters agree, record s as a match. The moment any character disagrees, abandon this shift and slide one step to the right (s becomes s+1), starting the comparison over from the beginning of the pattern. There are about n-m+1 shifts to try, and each can take up to m comparisons, giving a worst case of O((n-m+1)*m), usually written O(n*m). The pain case is a text like "aaaa...a" with pattern "aaa...ab": at every shift you compare almost all of P before the final mismatch, wasting nearly all the work.
Naive matching is the honest baseline against which the clever algorithms are measured, and its flaw is precisely the lesson they teach. After a partial match that fails, naive matching throws away everything it just learned and re-reads characters it already saw. The Knuth-Morris-Pratt algorithm, the Z-algorithm, and Boyer-Moore all earn their speed by remembering that information and never re-examining a text character more than a constant number of times. Still, for short patterns or short texts, naive matching is simple, cache-friendly, and often perfectly good in practice — the O(n*m) worst case rarely strikes on natural-language text.
T = "abcabd", P = "abd". Shift 0: a=a, b=b, c vs d mismatch — slide. Shift 1: b vs a mismatch — slide. Shift 2: c vs a mismatch — slide. Shift 3: a=a, b=b, d=d — match at 3. Notice at shift 0 we already read 'abc' yet at shift 3 we re-read those same regions; that re-reading is exactly what smarter methods eliminate.
Every mismatch restarts the pattern from its first character — the source of the wasted O(n*m) work.
The worst case O(n*m) is real but pathological; on ordinary text mismatches usually happen on the first character or two, so naive matching often behaves like O(n). Do not over-engineer if your patterns and texts are short.