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
Post a Comment