Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
last_result = binary_search_by_recursion(
sorted_collection=sorted_collection, item=item, left=left, right=right
)
if last_result is None:
if last_result == -1:
return -1
return last_result

Expand Down
2 changes: 1 addition & 1 deletion searches/linear_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int:
-1
"""
if not (0 <= high < len(sequence) and 0 <= low < len(sequence)):
raise Exception("Invalid upper or lower bound!")
raise ValueError("Invalid upper or lower bound!")
if high < low:
return -1
if sequence[low] == target:
Expand Down
15 changes: 11 additions & 4 deletions sorts/merge_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ def merge(left: list, right: list) -> list:
:return: Merged result
"""
result = []
while left and right:
result.append(left.pop(0) if left[0] <= right[0] else right.pop(0))
result.extend(left)
result.extend(right)
left_idx = 0
right_idx = 0
while left_idx < len(left) and right_idx < len(right):
if left[left_idx] <= right[right_idx]:
result.append(left[left_idx])
left_idx += 1
else:
result.append(right[right_idx])
right_idx += 1
result.extend(left[left_idx:])
result.extend(right[right_idx:])
return result

if len(collection) <= 1:
Expand Down