Naive(T, P) n = length(T) m = length(P) for s = 0 to n-m O(n-m+1) if P[1..m] = T[s+1..s+m] O(m) then print "Pattern occurs with shift" s
Example
However, there is more information in a failed match: