Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronzhin-dmitry/07ee1e297f65a9203ecf3b8c66a0fe43 to your computer and use it in GitHub Desktop.
Save ronzhin-dmitry/07ee1e297f65a9203ecf3b8c66a0fe43 to your computer and use it in GitHub Desktop.
#Good old worst-case for naive algorithm. Let's run Rabin-Karp on it.
import time
needle = 'a'*1000 + 'b'
haystack = 'a'*10000 + 'b'
result = []
start = time.time()
for i in range(50):
result = search_Rabin_Karp(needle, haystack)
end = time.time()
print('Positions:',result)
print('Time elapsed:',end-start)
#Example output:
#Positions: [9000]
#Time elapsed: 0.8732948303222656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment