Bitonic Sort

Bitonic Sort is an $$O(n \log^2 n)$$ sort. it can be implemented as a sorting network, meaning it is unstable, not adaptive, and uses $$O(1)$$ memory.

= Explanation =

Bitonic sequences
A bitonic sequence is a sequence that is first increasing, then decreasing (or vice versa).

An example of a bitonic sequence: [2,3,4,1]

This is also a bitonic sequence: [9,8,4,2,5,6]

This is NOT a bitonic sequence: [8,6,4,5,3,2]

= Pseudocode = procedure bitonic_sort(array arr) do for k = 2, k <= length(arr), k *= 2 do for j = k / 2, j > 0, j /= 2 do for i = 0 to length(arr) - 1 do int l = i XOR j            if ((i AND k) == 0 and arr[l] < arr[i]) or ((i AND k) != 0 and arr[i] < arr[l]) do swap arr[i] and arr[l] end if end for end for end for end