Quicksort algorithms with an early exit for sorted subfiles

  • Authors:
  • Roger L. Wainwright

  • Affiliations:
  • The University of Tulsa

  • Venue:
  • CSC '87 Proceedings of the 15th annual conference on Computer Science
  • Year:
  • 1987

Quantified Score

Hi-index 0.02

Visualization

Abstract

The Quicksort algorithm is known to be one of the most efficient internal sorting techniques. Quicksort has received considerable attention almost from the moment of its invention. This paper reviews some of the important improvements to Quicksort that have appeared in the literature. Historically, the improvements to Quicksort have been in one of the following areas: (1) algorithms for determining a better pivot value, (2) algorithms that consider the size of the generated subfiles, and (3) various schemes used to partition the file. Despite improvements in these areas, the worst case situation of &Ogr;(n2) comparisons for sorted or nearly sorted files still remains. This paper proposes a fourth research area for Quicksort improvement designed to remove the worst case behavior due to sorted or nearly sorted files. During the partitioning process (using any scheme) determine if the left and right subfiles are in sorted order. This is a minor but very effective modification to the Quicksort algorithm. A new Quicksort algorithms, Qsorte, is presented that provides an early exit for sorted subfiles. Test results on randomly generated lists, nearly sorted lists, sorted and sorted lists in reverse order are given for Quicksort, Quickersort, Bsort, Qsorte and several other algorithms. Results show Qsorte performs just as well as Quicksort for random files and in addition has &Ogr;(n) comparisons for sorted or nearly sorted files and &Ogr;(n) comparisons for sorted or nearly sorted files in reverse.