Naive Pattern Matching
Try every alignment and compare left to right, throwing away what was read at each mismatch.
String Matching: Naive, every shift
Shift 0: pattern under "abcabc". 5 agree, then 'c' differs from 'd'. Move on to shift 1.
Cost
- Best
- O(n)
- Average
- O(n + m)
- Worst
- O(n * m)
- Space
- O(1)
Before this
Leads to
Topics that need this one first.
Taught by the same lesson
String Matching covers these too, in the same run.