Modern comparison sorts like quicksort suffer from performance inconsistencies due to suboptimal pivot selection, leading to $(O(N^2))$ worst-case complexity, while in-place merge sort variants face challenges with data movement overhead. We introduce Wave Sort, a novel in-place sorting algorithm that addresses these limitations through a dynamic pivot selection strategy. Wave Sort iteratively expands a sorted region and selects pivots from this growing sorted portion to partition adjacent unsorted data. This approach ensures robust pivot selection irrespective of dataset size, guarantees a logarithmic recursion stack depth, and enables efficient in-place sorting. Our analysis shows a best comparison complexity of $(N-1)$, average comparison complexity close to $(\log_2(N)!)$, and worst-case comparison complexity bounded by $(O(N(\log(N))^2))$ with a small constant factor, which could be reduced to $(O(N\log(N)))$ with hybrid sorting. The algorithm can be easily expanded to be hybridized with other sorting algorithms. Experimental results demonstrate that Wave Sort requires significantly fewer comparisons than quicksort on average (approximately 24% less) and performs close to the theoretical minimum $(\log_2(N)!)$. Wave Sort offers a compelling alternative for applications demanding consistent, predictable, and in-place sorting performance.
翻译:现代比较排序算法(如快速排序)由于枢轴选择欠佳而存在性能不一致的问题,导致最坏情况复杂度为 $(O(N^2))$,而原地归并排序变体则面临数据移动开销的挑战。我们提出 Wave Sort,一种新颖的原位排序算法,通过动态枢轴选择策略解决了这些限制。Wave Sort 迭代地扩展已排序区域,并从这一不断增长的已排序部分中选择枢轴来划分相邻的未排序数据。这种方法确保了无论数据集大小如何都能进行稳健的枢轴选择,保证了递归栈深度的对数级,并实现了高效的原位排序。我们的分析表明,其最佳比较复杂度为 $(N-1)$,平均比较复杂度接近 $(\log_2(N)!)$,最坏情况比较复杂度受限于 $(O(N(\log(N))^2))$ 且常数因子较小,通过混合排序可进一步降低至 $(O(N\log(N)))$。该算法可以轻松扩展以与其他排序算法混合使用。实验结果表明,Wave Sort 平均所需的比较次数显著少于快速排序(约减少 24%),且性能接近理论最小值 $(\log_2(N)!)$。对于要求一致、可预测且原地排序性能的应用,Wave Sort 提供了一个引人注目的替代方案。