Created
December 4, 2015 17:20
-
-
Save rkhapov/c56b698ae0b3f7f7ba83 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
#Оцениваем производительность бинарного поиска на примере сравнения с линейным | |
#Пусть binsearch.py лежит в текущей директории | |
#Ссылка на binserach - https://gist.github.com/rkhapov/c9507eaa2afb1683fcbb | |
from binsearch import bin_search | |
#Пусть linesearch.py лежит в текущей директории | |
#Ссылка на linesearch - https://gist.github.com/rkhapov/f9726978ec001dedf9fc | |
from linesearch import line_search | |
from random import randint | |
#Выводим количество итераций для списков разной длинны | |
for i in range(10): | |
a = [0] | |
for j in range(10**i): | |
a.append(a[len(a)-1] + randint(0, 30)) | |
rb, tb = bin_search(a, a[len(a)-1], 0, len(a)) | |
rl, tl = line_search(a, a[len(a)-1]) | |
print("Size: ", len(a), "\n\t", end = "") | |
print("binary search: result -> ", rb, " time -> ", tb, end = "\n\t") | |
print("line search: result -> ", rl, " time -> ", tl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment