upd
This commit is contained in:
15
algorithms/labs/lab8/code/comp/1.py
Normal file
15
algorithms/labs/lab8/code/comp/1.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def choose_search_strategy(n, q):
|
||||
cost_linear = q * n
|
||||
cost_binary = n * (n.bit_length()) + q * (n.bit_length())
|
||||
cost_hash = n + q
|
||||
if cost_linear <= cost_binary and cost_linear <= cost_hash:
|
||||
return "linear"
|
||||
if cost_binary <= cost_hash:
|
||||
return "binary_search_with_sort"
|
||||
return "hash_table"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(choose_search_strategy(10**3, 1))
|
||||
print(choose_search_strategy(10**5, 100))
|
||||
print(choose_search_strategy(10**6, 10**6))
|
||||
Reference in New Issue
Block a user