bitonic sort is sorting algorithm to use multiple process but this code not containing parallel process it can sort only array that sizes power of 2 it can sort array in both increasing order and decreasing order by giving argument trueincreasing and falsedecreasing worstcase in parallel ologn2 worstcase in nonparallel onlogn2 reference https en wikipedia orgwikibitonicsorter end of functioncompare and bitionicmerge definition checks if n is power of two bitonic sort is sorting algorithm to use multiple process but this code not containing parallel process it can sort only array that sizes power of 2 it can sort array in both increasing order and decreasing order by giving argument true increasing and false decreasing worst case in parallel o log n 2 worst case in non parallel o nlog n 2 reference https en wikipedia org wiki bitonic_sorter end of function compare and bitionic_merge definition checks if n is power of two
def bitonic_sort(arr, reverse=False):
    
    def compare(arr, reverse):
        n = len(arr)//2
        for i in range(n):
            if reverse != (arr[i] > arr[i+n]):
                arr[i], arr[i+n] = arr[i+n], arr[i]
        return arr

    def bitonic_merge(arr, reverse):
        n = len(arr)
        
        if n <= 1:
            return arr
        
        arr = compare(arr, reverse)
        left = bitonic_merge(arr[:n // 2], reverse)
        right = bitonic_merge(arr[n // 2:], reverse)
        return left + right
    
    
    n = len(arr)
    if n <= 1:
        return arr
    
    if not (n and (not(n & (n - 1))) ):
        raise ValueError("the size of input should be power of two")
    
    left = bitonic_sort(arr[:n // 2], True)
    right = bitonic_sort(arr[n // 2:], False)

    arr = bitonic_merge(left + right, reverse)
        
    return arr