Created
January 30, 2023 13:47
-
-
Save ronzhin-dmitry/07ee1e297f65a9203ecf3b8c66a0fe43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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