AlgoScope

Naive Pattern Matching

Try every alignment and compare left to right, throwing away what was read at each mismatch.

String algorithms, algorithm, beginner
Mismatch at offset 5 of shift 0.txtpatabcabcabdabcabdc < d

String Matching: Naive, every shift

Decision, step 2 of 6

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.