The alphabet contains only two numbers, for example
[0, 0, 1, 1, 0, 1, 0, 1]
and it can be really big (at least millions) I need to soften it with swap operations (when I swap, I will also make the same changes in adjacent data structures). Sorting must also be stable.
In my case, the swap operation is expensive, the sorting algorithm should also minimize them.
O (n) additional spatial complexity is acceptable if the number of swaps is significantly reduced.
What is the best sorting algorithm in this case?
source
share