An Explicit and Efficient $O(n^2)$-Time Algorithm for Sorting Sumsets
S. Mundhra
TL;DR
This work resolves the long-standing open problem of sorting the sumset $Z$ of two sorted sequences $X$ and $Y$ in the optimal $O(n^2)$ time and comparison count. It introduces an explicit fixed algorithm that leverages the structured sumset matrix, via forward-scanning insertion with a lookahead invariant, to achieve amortized constant-time insertions and no $\log n$ overhead. The approach extends naturally to $k$-fold sumsets with $O(n^k)$ complexity and provides a concrete RAM-model algorithm, supported by empirical benchmarks that show speedups over classical sorting methods for large inputs. The paper also discusses a dynamic maintenance conjecture and practical considerations for data-structure choices, aiming to broaden applicability in computational geometry and related domains.
Abstract
We present the first explicit comparison-based algorithm that sorts the sumset $X + Y = \{x_i + y_j,\ \forall 0 \le i, j < n\}$, where $X$ and $Y$ are sorted arrays of real numbers, in optimal $O(n^2)$ time and comparisons. While Fredman (1976) proved the theoretical existence of such an algorithm, a concrete construction has remained open for nearly five decades. Our algorithm exploits the structured monotonicity of the sumset matrix to perform amortized constant-comparisons and insertions, eliminating the $\log(n)$ overhead typical of comparison-based sorting. We prove correctness and optimality in the standard comparison model, extend the method to $k$-fold sumsets with $O(n^k)$ performance, and outline potential support for dynamic updates. Experimental benchmarks show significant speedups over classical algorithms such as MergeSort and QuickSort when applied to sumsets. These results resolve a longstanding open problem in sorting theory and contribute novel techniques for exploiting input structure in algorithm design.
