MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / bitonic_sort

Function bitonic_sort

sorts/bitonic_sort.py:65–84  ·  view source on GitHub ↗

This function first produces a bitonic sequence by recursively sorting its two halves in opposite sorting orders, and then calls bitonic_merge to make them in the same order. >>> arr = [12, 34, 92, -23, 0, -121, -167, 145] >>> bitonic_sort(arr, 0, 8, 1) >>> arr [-167, -

(array: list[int], low: int, length: int, direction: int)

Source from the content-addressed store, hash-verified

63
64
65def bitonic_sort(array: list[int], low: int, length: int, direction: int) -> None:
66 """
67 This function first produces a bitonic sequence by recursively sorting its two
68 halves in opposite sorting orders, and then calls bitonic_merge to make them in the
69 same order.
70
71 >>> arr = [12, 34, 92, -23, 0, -121, -167, 145]
72 >>> bitonic_sort(arr, 0, 8, 1)
73 >>> arr
74 [-167, -121, -23, 0, 12, 34, 92, 145]
75
76 >>> bitonic_sort(arr, 0, 8, 0)
77 >>> arr
78 [145, 92, 34, 12, 0, -23, -121, -167]
79 """
80 if length > 1:
81 middle = int(length / 2)
82 bitonic_sort(array, low, middle, 1)
83 bitonic_sort(array, low + middle, middle, 0)
84 bitonic_merge(array, low, length, direction)
85
86
87if __name__ == "__main__":

Callers 1

bitonic_sort.pyFile · 0.85

Calls 1

bitonic_mergeFunction · 0.85

Tested by

no test coverage detected