P h d Thesis Author: Tomi Pasanen Title: In-Place AlgorithMs for Sorting Problems Supervisors: Jyrki Katajalnen and Jukl~ Teuhola D a t e o f D e f e n c e : April 10, 1999 I n s t i t u t i o n g r a n t i n g d e g r e e : University of Turku, Finland Abstract A n algorithm is said to operate in-place if it uses only a constant amount of extra memory for storing local variables besides the m e m o r y reserved for the input elements. In other words, the size of the extra m e m o r y does not grow as the number of input elements, n, gets larger,but it is bounded by a constant. A n algorithm reorders the input elements stably if the originalrelativeorder of equal elements is retained. In this thesis,we devise in-place algorithnm for sorting and related problems. W e measure the ei~ciency of the algorithms by calculating the nnmber of element comparisons and element moves performed in the worst case in the following. The amount of index m~nlpnlation operations is closely related to these quantities, so it is omitted in our calculations. W h e n no precise figures are needed, we denote the sum of all operations by a general expression "time". The thesis consists of five separate articles,the main contributions of which are described below. W e construct algorithms for stable partitioning and stable selection which are the first linear-time algorithms being both stable and in-place concurrently. Moreover, we define problems stable unpartitioning and restoring selection and devise linear-time algorithms for these problems. The algorithm for stable unpartitioning is in-place while that for restoring selection uses O(n) extra bits. By using these algorithms as subroutines we construct an adaption of Quicksort that sorts a multiset stably in O(~-~= 1 ml log(n/ml)) time where m~ is the multiplicity of ith distinct element for i : 1, . . , k. This is the first in-place algorithm that sorts a mu]tiset stably in asymptotic~ly optimal time. We present in-place algorithms for unstable and stable merging. The algorithm.q 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 most m(t + 1) -F- n/2 ~ + o(m) comparisons where m _< n and t = Llog(n/m)J. The previous best results were 1.125(n + m) + o(n) comparisons and 5(n + m) + o(n) moves for unstable merging, and 16.5(n + m) + o(n) moves for stable merging. Finally, we devise two in-place algorithms for sorting. Both algorithm~ axe adaptions of Mergesort. The first performs n l o g z n + O(n) comparisons and z n l o g 2 n + O(nloglogn) moves for any fixed 0 < z ~ 2. Our experiments show that this algorithm performs well in practice. The second requires n l o g 2 n + O(n) comparisons and fewer than O(nlogn/loglogn) moves. This is the first in-place sorting algorithm that performs o(n log n) moves in the worst case while guaranteeing O(n log n) comparisons. This Ph.D. Thesis has been printed as T U C S Dissertationno. 15 (March 1999) of Turku Centre for Computer Science, Turku Finland. Author's Correspondence Address: Tomi Pasanen Turku Centre for Computer Science Lemmink~isenlcAtu 14 A FIN-20520 Turku, FINLAND Email: t p a s a n s n @ c s . u t u . f i W~: h t t p : / / ~ w 2 , ca. u t u . f i / s t a f f / t o m i , p a s a n e n /
/lp/association-for-computing-machinery/in-place-algorithms-for-sorting-problems-IF9FhOQi6x