In-place algorithms for sorting problems

  • Authors:
  • Tomi Pasanen

  • Affiliations:
  • Turku Centre for Computer Science, Turku, Finland

  • Venue:
  • ACM SIGACT News
  • Year:
  • 1999

Quantified Score

Hi-index 0.00

Visualization

Abstract

An algorithm is said to operate in-place if it uses only aconstant amount of extra memory for storing local variables besidesthe memory reserved for the input elements. In other words, thesize of the extra memory does not grow as the number of inputelements, n, gets larger, but it is bounded by aconstant. An algorithm reorders the input elements stably if theoriginal relative order of equal elements is retained.In this thesis, we devise in-place algorithms for sorting andrelated problems. We measure the efficiency of the algorithms bycalculating the number of element comparisons and element movesperformed in the worst case in the following. The amount of indexmanipulation operations is closely related to these quantities, soit is omitted in our calculations. When no precise figures areneeded, we denote the sum of all operations by a general expression"time". The thesis consists of five separate articles, the maincontributions of which are described below.We construct algorithms for stable partitioning and stableselection which are the first linear-time algorithms being bothstable and in-place concurrently. Moreover, we define problemsstable unpartitioning and restoring selection and deviselinear-time algorithms for these problems. The algorithm for stableun-partitioning is in-place while that for restoring selection usesO(n) extra bits. By using these algorithms assubroutines we construct an adaption of Quicksort that sorts amultiset stably inO(Σki= 1 milog(n/mi)) time wheremi is the multiplicity ofith distinct element for i = 1,..,k. This is the first in-place algorithm thatsorts a multiset stably in asymptotically optimal time.We present in-place algorithms for unstable and stable merging.The algorithms are asymptotically more efficient than earlier ones:the number of moves is 3(n +m)+o(m) for the unstable algorithm,5n+12m+o(m)for the stable algorithm, and the number of comparisons at mostm(t + 1) +n/2t +o(m) comparisons where m≤ n and t =[log(n/m)]. The previous best results were1.125(n + m) +o(n) comparisons and5(n + in) + o(n) moves forunstable merging, and 16.5(n + in) +o(n) moves for stable merging.Finally, we devise two in-place algorithms for sorting. Bothalgorithms are adaptions of Mergesort. The first performsn log2n + O(n) comparisons andε n loge n +O(n log log n) moves for anyfixed 0 < ε ≤ 2. Our experiments show thatthis algorithm performs well in practice The second requiresn loge n +O(n) comparisons and fewer thanO(n log n/log logn) moves. This is the first in-place sortingalgorithm that performs o(nlog n) moves in the worst case whileguaranteeing O(n log n)comparisons.