We give a more space-efficient implementation of adaptive mergesort: Virtual-Memory Powersort. Using internal buffering techniques, we significantly reduce the memory consumption of the algorithm; specifically, for sorting $n$ objects the required buffer area is reduced from space for $n/2$ objects to $O(\sqrt{n \log n})$ objects. While this space-efficiency can be achieved (indeed reduced to $O(1)$) conceptually very easily with known inplace merging algorithms, using these as a drop-in replacement for the standard merge algorithm incurs a substantial slow-down. Virtual-Memory Powersort, by contrast, uses the same number of moves and comparisons as previous Powersort implementations up to an additive $O(n)$ term. We report on an empirical running-time study comparing our implementation against other Powersort variants and state-of-the-art stable sorting methods, demonstrating that almost in-place stable sorting can be achieved with negligible overhead in many scenarios.
翻译:我们提出了一种更节省空间的自适应归并排序实现:虚拟内存Powersort。通过采用内部缓冲技术,我们显著降低了该算法的内存消耗;具体而言,对于排序$n$个对象,所需缓冲区空间从$n/2$个对象的空间减少至$O(\sqrt{n \log n})$个对象。虽然这种空间效率(实际上可降至$O(1)$)在概念上可以通过已知的就地归并算法非常简易地实现,但直接将此类算法作为标准归并算法的替代品会带来显著的性能下降。相比之下,虚拟内存Powersort在移动次数和比较次数上与先前的Powersort实现保持一致,仅存在一个$O(n)$项的额外增量。我们报告了一项实证运行时间研究,将我们的实现与其他Powersort变体及最先进的稳定排序方法进行对比,证明在众多场景下,几乎无需额外开销即可实现近乎原地的稳定排序。