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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -