python - Runtime of brute force string-matching algorithm -


i've written small, quick (to write, not run!), algorithm string matching in python:

def brutematch(n,m):     in range(0,len(n)-len(m)+1):         if n[i:len(m)+i]==m:             return(i) 

would runtime algorithm o(nm)? i'm comparing worst-case runtime horspool string-matching algorithm, (nm). guess confusion stems fact algorithm appears o(n) runtime iterates through input n, using indices inputs slice notation equality statement? thoughts?

worst case o(nm), yes. because, see, == test tests each character in each string, take long length of shortest string in equality test.


Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -