Table of Contents
Fetching ...

How to Sort in a Refrigerator: Simple Entropy-Sensitive Strictly In-Place Sorting Algorithms

Ofek Gila, Michael T. Goodrich, Vinesh Sridhar

TL;DR

This paper provides the first comparison-based sorting algorithms that are strictly in-place and have a running time that is optimal in terms of the run-based entropy, H(A), of an input array, A, of size n.

Abstract

While modern general-purpose computing systems have ample amounts of memory, it is still the case that embedded computer systems, such as in a refrigerator, are memory limited; hence, such embedded systems motivate the need for strictly in-place algorithms, which use only O(1) additional memory besides that used for the input. In this paper, we provide the first comparison-based sorting algorithms that are strictly in-place and have a running time that is optimal in terms of the run-based entropy, H(A), of an input array, A, of size n. In particular, we describe two remarkably simple paradigms for implementing stack-based natural mergesort algorithms to be strictly in-place in O(n(1 + H(A))) time.

How to Sort in a Refrigerator: Simple Entropy-Sensitive Strictly In-Place Sorting Algorithms

TL;DR

This paper provides the first comparison-based sorting algorithms that are strictly in-place and have a running time that is optimal in terms of the run-based entropy, H(A), of an input array, A, of size n.

Abstract

While modern general-purpose computing systems have ample amounts of memory, it is still the case that embedded computer systems, such as in a refrigerator, are memory limited; hence, such embedded systems motivate the need for strictly in-place algorithms, which use only O(1) additional memory besides that used for the input. In this paper, we provide the first comparison-based sorting algorithms that are strictly in-place and have a running time that is optimal in terms of the run-based entropy, H(A), of an input array, A, of size n. In particular, we describe two remarkably simple paradigms for implementing stack-based natural mergesort algorithms to be strictly in-place in O(n(1 + H(A))) time.
Paper Structure (26 sections, 22 theorems, 6 equations, 15 figures, 1 table, 8 algorithms)

This paper contains 26 sections, 22 theorems, 6 equations, 15 figures, 1 table, 8 algorithms.

Key Result

lemma 1

The collapse phase of any stack-based mergesort $\mathcal{S}$ can be implemented in-place using the walk-back algorithm with only a constant-factor increase in runtime.

Figures (15)

  • Figure 1: A merge step according to a merge policy, $\mathcal{P}$. The merged run takes the label of the higher run. Merging decreases the labels of all runs below the two merged runs.
  • Figure 2: The walk-back algorithm applied to an almost-3-aware mergesort. We currently know the lengths of the runs labeled $R_1$ and $R_2$. There may be $O(\log n)$ runs to the left of $R_2$ in the array (our "stack" of runs), but we do not maintain any information about them. Whenever we need to know the length of $R_3$, we start walking backwards from the start of $R_2$. Surprisingly, this strategy only increases runtime by a constant factor in several stack-based mergesorts.
  • Figure 3: Each index in the array is associated with a power value, where the power of an index is the depth of the corresponding tree node (depicted above it). Each run is associated with the smallest power value of any index between its midpoint and the midpoint of the next run, i.e. its power interval$I$. The power intervals $I_3$ and $I_2$ define powers $p_3$ and $p_2$. They are depicted under their respective runs. $R_1$, being the top run, does not yet have an assigned power.
  • Figure 4: Merging runs $R_2$ and $R_3$ causes $I_2$ and $I_4$ to extend into what used to be $I_3$. Nevertheless, when $R_2$ and $R_3$ are merged, $p_3 > p_2$ and $p_3 \geq p_4$. Therefore, the powers of $I'_4$ and $I'_2$ do not change.
  • Figure 5: The result of performing partitioning to move all short runs to the end of the array. All runs to the left of the gray block are of size $> 3\lambda$. The elements in the gray block belonged to runs of size $\leq 3\lambda$. Their ordering may not be preserved.
  • ...and 10 more figures

Theorems & Definitions (40)

  • lemma 1
  • lemma 2
  • proof
  • proof
  • lemma 3
  • proof
  • lemma 4
  • proof
  • lemma 5
  • proof
  • ...and 30 more