Skip to content

Commit 5ede257

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4235f83 commit 5ede257

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

searches/binary_search.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def binary_search(sorted_collection: list[int], item: int) -> int:
130130
"""
131131
if any(a > b for a, b in pairwise(sorted_collection)):
132132
raise ValueError("sorted_collection must be sorted in ascending order")
133-
133+
134134
left = 0
135135
right = len(sorted_collection) - 1
136136
result = -1
@@ -187,7 +187,7 @@ def binary_search_by_recursion(
187187
"""
188188
if right < 0:
189189
right = len(sorted_collection) - 1
190-
190+
191191
# Base case: range is empty
192192
if right < left:
193193
return -1
@@ -198,10 +198,12 @@ def binary_search_by_recursion(
198198
# We found a match! Now see if there's an earlier one to the left.
199199
# CRITICAL: Only recurse if there is actually space to the left
200200
if midpoint > left:
201-
res = binary_search_by_recursion(sorted_collection, item, left, midpoint - 1)
201+
res = binary_search_by_recursion(
202+
sorted_collection, item, left, midpoint - 1
203+
)
202204
return res if res != -1 else midpoint
203205
return midpoint
204-
206+
205207
elif sorted_collection[midpoint] > item:
206208
return binary_search_by_recursion(sorted_collection, item, left, midpoint - 1)
207209
else:
@@ -251,6 +253,9 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
251253
print(
252254
f"{name:>26}:",
253255
timeit.timeit(
254-
f"{name}(list(collection), 500)", setup=setup, number=5_000, globals=globals()
256+
f"{name}(list(collection), 500)",
257+
setup=setup,
258+
number=5_000,
259+
globals=globals(),
255260
),
256-
)
261+
)

0 commit comments

Comments
 (0)