Odd-Even Merge Sort

Odd-Even Merge Sort is an $$O(n \log^2 n)$$ sort that can be implemented as a sorting network, making it not Adaptive, not Stable, and take $$O(1)$$ space.

Odd-Even Merge Sort is fundamentally similar to Bitonic Sort, both being merge sorting networks that have an $$O(n \log n)$$ merge. Like Bitonic Sort, it can be fully parallelized yielding $$O(\log^2 n)$$ time. It also has Recursive and Iterative versions like many merge sorts.

= Explanation = The Odd-Even Merge is an unstable $$O(n \log n)$$ merge process that relies exclusively on compare-and-swaps. it works as following:

For decreasing powers of 2, compare and swap an element in the first subarray and its corresponding one in the second starting at n - the power of two.

Odd-Even merge sort is identical to a Bottom-Up Merge Sort with the merge replaced by an Odd-Even Merge.

= Example = Odd-Even Merge Sort the list [7 5 1 4 8 2 3 6]. First, merge the pairs. [5 7 1 4 2 8 3 6] └─┘ └─┘ └─┘ └─┘ Next, merge pieces of size 4. [5 7] [1 4] └─────┘     └─────┘ [1 5 4 7]    └─┘ [1 4 5 7] Repeat. [1 4 5 7 2 3 6 8]         └─────┘ [1 2 3 4 5 6 7 8]  └─────────────┘