Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions searches/exponential_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,19 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
1
>>> exponential_search([0, 5, 7, 10, 15], 6)
-1
>>> exponential_search([], 1)
-1
>>> exponential_search([1, 1], -1)
-1
"""
if list(sorted_collection) != sorted(sorted_collection):
raise ValueError("sorted_collection must be sorted in ascending order")

if not sorted_collection:
return -1

if sorted_collection[0] > item:
return -1
if sorted_collection[0] == item:
return 0

Expand Down