5.
In this paper, we describe an algorithm to stably sort an array of
n elements using only a linear number of data movements and constant extra space, albeit in quadratic time. It was not known previously whether such an algorithm existed. When the input contains only a constant number of distinct values, we present a sequence of
in situ stable sorting algorithms making
O(
n lg
(k+1)
n+
kn) comparisons (lg
(K) means lg iterated
k times and lg* the number of times the logarithm must be taken to give a result 0) and
O(
kn) data movements for any fixed value
k, culminating in one that makes
O(
n lg*
n) comparisons and data movements. Stable versions of quicksort follow from these algorithms.Research supported by Natural Sciences and Engineering Research Council of Canada grant No.A-8237 and the Information Technology Research Centre of Ontario.Supported in part by a Research Initiation Grant from the Virginia Engineering Foundation.
相似文献