Odd-Even Sort
- Ω( n )
- Θ( n2 )
- O( n2 )
- space O( 1 )
Array
Comparator strip
Index down, time to the right
- Comparisons count only element-against-element checks; loop and index checks are never counted.
- Reads and writes include reads and writes to helper buffers (merge, counting, radix, bucket and tim sort).
- A swap counts once, as a swap. It is never also counted as a read or a write.
- Real time is the average time of the counted sort on this device over repeated runs, measured once before playback and independent of animation speed. Visual time is the time spent animating, excluding pauses.
How odd-even sort works
Odd-even sort alternates two phases. The odd phase compares and swaps the pairs (1,2), (3,4), ... and the even phase does the same for (0,1), (2,3), ... It stops when a full round makes no swap.
Read more
Every pair inside a phase is independent, so on parallel hardware each phase takes constant time. Run sequentially, as here, it is a bubble sort variant with O(n²) comparisons.
| Best time | Ω( n ) | good |
|---|---|---|
| Average time | Θ( n2 ) | poor |
| Worst time | O( n2 ) | poor |
| Worst space | O( 1 ) | good |
Big O notation gives the lower, average and upper bounds of an algorithm. Time complexity bounds the number of operations; space complexity bounds the extra memory it uses.