We establish a lower bound of B(n) = n「log n」-2~「log n」+ 1~1 on the number of comparisons performed by any algorithm that uses priority queues to sort n elements. Three sorting algorithms using priority queues are introduced. The first algorithm performs the same comparisons as the classical Mergesort algorithm, but in a different order. The second algorithm performs at most 2nlogn+O(n) comparisons, with the advantage of being adaptive; meaning that it runs faster when the input equence has some presortedness. In particular, we show that this algorithm sorts an already sorted sequence in linear time; a fact that is not obvious since there is no special checks to guarantee this behavior. The third algorithm is almost implicit; it can be implemented using the input array and less than n extra bits. The number of comparisons performed by this algorithm is at most B(n) + 2.5ri. The three algorithms have the advantage of producing every element of the sorted output, after the first, in O(logn), and can be implemented to be practically efficient.
展开▼