arXiv:2611.01157cs.DSOct 2026

Manuscript Offprint

arXiv:2611.01157

The Movement Complexity of Sorting

Sichen Wang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

The complexity of sorting is usually measured by the number of comparisons. This measure ignores the movement of the read heads between comparisons, which is a real cost on many machines. We study this cost on its own. Keys lie on a dd-dimensional grid, two heads move over the grid and compare the keys beneath them, and the only cost is the total movement of the heads. The algorithm plans its route in rr rounds and sees the outcomes of each round only after running it. For every dd and rr we determine the expected movement needed to sort nn keys: it is nβn^{\beta} up to polylogarithmic factors, where β=1+Dr−1/(Dr−(D−1)r)\beta = 1 + D^{r-1}/(D^r - (D-1)^r) and D=2dD = 2d, falling from n2n^2 at r=1r = 1 to n1+1/(2d)n^{1+1/(2d)} with unlimited rounds. Our algorithm makes every round move about the same amount, and a matching lower bound holds against every algorithm.

1 Introduction

The comparison model counts comparisons and nothing else, which for sorting gives the classical Θ(nlog⁡n)\Theta(n \log n). This count is not the whole cost of sorting. On general sequential models the product of time and space for sorting is Ω(n2/log⁡n)\Omega(n^2/\log n) [BC82], later strengthened to Ω(n2)\Omega(n^2) [Bea91]. On many machines the further cost is travel, because the two keys of a comparison must first be brought within reach. On a Turing machine with one worktape and a two-way read-only input tape, sorting an input of NN bits, made of strings of 3log⁡N3 \log N bits each, takes Ω(N3/2/log⁡N)\Omega(N^{3/2}/\sqrt{\log N}) steps [MS86; DMS91]. This bound comes from the distance the heads must travel: two heads on tapes of length tt need Ω(t3/2)\Omega(t^{3/2}) steps to reach the pairs of tape positions given by a well-scattered permutation [DMS91].

Adaptivity has its own classical measure. In the parallel comparison model [Val75], an algorithm commits a set of comparisons in each round and learns the outcomes when the round ends, and the exponents of the number of comparisons for sorting, selection, and merging in rr rounds are known [Val75; BT83; HH82; AAV86; AA88; Pip87; BB90]. This theory charges nothing for moving between comparisons, and the bounds on travel above say nothing about rounds. We ask: How much must a processor travel to sort nn keys it cannot move, if it plans its route in rr rounds and learns the outcomes of each round only after running it?

We study the simplest model with this cost. The nn keys lie one at each position of the grid [m]d[m]^d, where n=mdn = m^d, and they carry a hidden total order. Two heads move over the grid in unit steps, and the algorithm learns about the order only by comparing the two keys beneath the heads. It must output the list of positions in increasing order of rank. The positions of the two heads form a point of the comparison grid [m]2d[m]^{2d}, and two keys are compared when this point reaches their pair of positions, in either order. An rr-round algorithm commits a route at the start of each round, as a function of its coins and of the outcomes of earlier rounds, and it receives the outcomes at all points of the route only after running it. Comparisons, computation, and memory are free, and the only cost is the movement, the total ℓ1\ell_1 distance the heads move. The algorithm must be correct on every input and for every outcome of its coins, and Mr(d)(n)M_r^{(d)}(n) is the least expected movement on a worst input. For r=∞r=\infty the number of rounds is free. Section 2.1 gives the precise definition. The grid is the basic metric space of polynomial growth, and the proofs use little beyond the sizes of its balls and its partitions into cubes and boxes.

Two baselines bound the answer. For r=1r=1, the oblivious case, the single route is fixed in advance and must compare all (n2)\binom{n}{2} pairs, so M1(d)(n)=Θ(n2)M_1^{(d)}(n) = \Theta(n^2). For r=∞r=\infty, the fully adaptive case, a merge sort attains O(n1+1/(2d))O(n^{1+1/(2d)}), and this matches the lower bound of Proposition 4.5.

Problem. For every dimension dd and every round budget rr, determine Mr(d)(n)M_r^{(d)}(n), the least worst-case expected movement with which an rr-round algorithm sorts nn keys on [m]d[m]^d.

References (33)