[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2024-10-16 20:04:45 +00:00
parent c8397d47cf
commit ddfcaecb77

View File

@ -17,7 +17,7 @@
"""
if len(sequence) < 2:
return sequence
aux = sequence[:]
print(f"Initial sequence: {sequence}")
adaptive_merge_sort_helper(sequence, aux, 0, len(sequence) - 1)
@ -41,18 +41,18 @@ def adaptive_merge_sort_helper(array: list, aux: list, low: int, high: int) -> N
"""
if high <= low:
return
mid = (low + high) // 2
print(f"Sorting: array[{low}:{mid + 1}] and array[{mid + 1}:{high + 1}]")
adaptive_merge_sort_helper(aux, array, low, mid)
adaptive_merge_sort_helper(aux, array, mid + 1, high)
if array[mid] <= array[mid + 1]:
print(f"Skipping merge as array[{mid}] <= array[{mid + 1}]")
array[low:high + 1] = aux[low:high + 1]
return
merge(array, aux, low, mid, high)
@ -65,7 +65,7 @@ def merge(array: list, aux: list, low: int, mid: int, high: int) -> None:
After merge: [1, 2, 3, 4]
"""
print(f"Merging: array[{low}:{mid + 1}] and array[{mid + 1}:{high + 1}]")
i, j = low, mid + 1
for k in range(low, high + 1):
if i > mid:
@ -80,10 +80,10 @@ def merge(array: list, aux: list, low: int, mid: int, high: int) -> None:
else:
aux[k] = array[j]
j += 1
for k in range(low, high + 1):
array[k] = aux[k]
print(f"After merge: {array[low:high + 1]}")