Online Sorting Problem: Algorithms and Analysis
- Online Sorting Problem is a family of tasks where ordering decisions are made in real time without complete input, featuring variants like stable sorting and array placement.
- It encompasses models based on comparisons, irrevocable array placements, and progressive strategies to minimize metrics such as adjacency cost and entropy-sensitive comparisons.
- Recent advances employ adaptive, tree-based, and stochastic methods to achieve near-optimal competitive ratios and improve sorting in multidimensional and anytime contexts.
Online sorting denotes a family of problems in which ordering decisions must be made before the full input is known. In the arXiv literature, the term is used for at least three distinct settings: comparison-based online stable sorting of a multiset, irrevocable placement of arriving values into an array so as to minimize a final adjacency cost, and progressive or anytime sorting in which queries or comparisons gradually refine a partial order. What unifies these settings is the online constraint: after each arrival or interaction, the algorithm must commit to an action without access to future data (0907.0741, Abrahamsen et al., 2024, 0907.1295, Caizergues et al., 2024).
1. Formal variants and problem definitions
A prominent contemporary formulation gives an array of initially empty cells and a stream of real numbers . Each item must be placed immediately and irrevocably into an empty cell, and the objective is to minimize the sum of absolute differences between consecutive placed values. When the array has slack, one common definition is
where are the filled indices in order; empty cells are ignored (Nirjhor et al., 20 Aug 2025). Closely related formulations consider an array of size with cost
(Abrahamsen et al., 2024), or define and and sum boundary terms as well (Aamand et al., 2021). In normalized inputs from containing both endpoints, the offline optimum is $1$ (Nirjhor et al., 20 Aug 2025).
A much older line of work studies online stable sorting by comparisons. There the input is a multiset of size 0, stability requires preservation of the relative order of equal elements, and the algorithm must keep the prefix seen so far in sorted order. The key parameters are the number 1 of distinct elements and the entropy
2
with all logarithms in base 3 (0907.0741).
The surveyed literature also contains progressive formulations in which the list is initially unsorted and online selection or search queries progressively sort it (0907.1295), and anytime formulations in which an algorithm must provide tentative estimates of the sorted order after any number of comparisons, with intermediate quality measured by Spearman’s footrule (Caizergues et al., 2024).
| Model | Online action | Representative guarantee |
|---|---|---|
| Online stable sorting | Keep the seen multiset in sorted order using comparisons | 4 ternary comparisons when 5 (0907.0741) |
| Array-placement online sorting | Place each arrival irrevocably into an array | Adversarial competitive ratio 6 for size-7 arrays (Abrahamsen et al., 2024) |
| Progressive or anytime sorting | Refine order through queries or comparisons | Total 8 for 9 unique queries; footrule-based intermediate estimates (0907.1295, Caizergues et al., 2024) |
2. Online stable sorting by comparisons
For online stable sorting with ternary comparisons, the sharpest asymptotic results in the surveyed material are entropy-sensitive. If 0, then a multiset 1 can be sorted online and stably using at most 2 ternary comparisons, and in the worst case at least 3 ternary comparisons are required (0907.0741). The bounds are therefore tight up to 4.
The upper bound is obtained by modifying Fredman’s online algorithm, based on a result of Mehlhorn, to use dynamically constructed entropy-weighted ternary search trees. The method does not require prior knowledge of the frequencies of the distinct elements. The lower bound uses an adversarial construction that forces any online stable sorting algorithm to pay essentially the same entropy-sensitive cost (0907.0741).
The same paper records analogous binary-comparison bounds: 5 comparisons are sufficient and 6 are necessary. It also compares the online result with the best known offline upper bound 7, concluding that online stable sorting with ternary comparisons matches the best known offline upper bound up to an 8 term (0907.0741).
These results are specific to the comparison model and should not be conflated with the array-placement problem. The shared phrase “online sorting” masks a substantial difference between maintaining sorted order by comparisons and constructing a low-cost final permutation by irrevocable placement.
3. Irrevocable array placement and adversarial competitive analysis
In the array-placement model, the central question is competitive ratio under adversarial arrival order. For the no-slack case 9, the strongest statement in the surveyed work is that the deterministic and randomized competitive ratio of online sorting is 0, and the lower bound 1 holds even for inputs from 2 (Abrahamsen et al., 2024). This settles the question of whether randomization improves the asymptotics in the basic one-dimensional adversarial model: it does not (Abrahamsen et al., 2024).
An earlier formulation, written as OnlineSorting3, already isolated the same core phenomenon. For 4, there exists an online algorithm with competitive ratio at most 5, and every online algorithm has competitive ratio at least 6 (Aamand et al., 2021). That work framed the problem as an ordering bottleneck for translational packing of convex polygons and used it to derive non-existence results for competitive online strip packing, bin packing, and perimeter packing algorithms (Aamand et al., 2021).
The adversarial proofs use adaptive constructions. In the lower-bound framework of OnlineSorting7, if a 8-competitive algorithm exists, then 9 (Aamand et al., 2021). For constant 0, this rules out constant competitiveness. In the exact-size case 1, the later 2 characterization shows that the fixed-space regime behaves very differently from the slack-space regime (Abrahamsen et al., 2024).
A related metric variant replaces absolute differences by a uniform metric, so the objective becomes minimizing the number of switches between consecutive items of different types. In that setting, the competitive ratio is 3 for both deterministic and randomized algorithms, and with a larger array of size 4 the ratio becomes 5 (Abrahamsen et al., 2024).
4. Extra space, nearly tight tradeoffs, and structural algorithms
The most substantial recent progress concerns arrays larger than 6. Earlier work gave, for 7 with 8, a deterministic competitive ratio
9
while the lower bound for 0 was 1 (Azar et al., 19 Aug 2025). This left an exponential gap.
A 2025 paper states that it bridges this exponential gap and almost completely resolves the online sorting problem. For 2, it gives a deterministic 3-competitive algorithm for any 4. For 5 where 6, it gives a deterministic 7-competitive algorithm (Azar et al., 19 Aug 2025). In particular, this implies an 8-competitive algorithm with 9 space, and yields an upper bound of 0 on the product of competitive ratio and 1, against the lower bound 2 on the same product (Azar et al., 19 Aug 2025).
The algorithms in that work are tree-based. For 3, the data structure uses composite trees and elementary trees; the array is partitioned into a prefix handled by a composite tree and a suffix consisting of 4 elementary trees. The analysis gives space 5 and cost 6, with 7 yielding the stated competitive ratio (Azar et al., 19 Aug 2025). For 8, the array is divided into 9 composite trees covering disjoint subintervals of 0, and routing each arrival to the tree for its subinterval yields the 1 bound (Azar et al., 19 Aug 2025). The same paper also gives unknown-range variants via doubling, incurring an extra 2 factor (Azar et al., 19 Aug 2025).
An independent 2025 analysis obtains a deterministic quasi-polylogarithmic cost
3
for the 4-cell model. Its main structural idea is recursive box placement in which the “array of boxes” itself becomes an online sorting instance, together with exponentially increasing 5 up the recursion (Nirjhor et al., 20 Aug 2025). This suggests that recursive slack management, rather than only local box fullness thresholds, is a decisive design principle in the slack-space regime.
5. Stochastic input, multidimensional extensions, and online TSP
When the input is stochastic rather than adversarial, the achievable guarantees improve sharply. An initial stochastic result assumes that the 6 are i.i.d. uniform on 7 and gives an online algorithm with competitive ratio 8 with high probability (Abrahamsen et al., 2024). That work explicitly notes connections between online sorting and the design of efficient hash tables (Abrahamsen et al., 2024).
Subsequent results reduce the cost to polylogarithmic or near-polylogarithmic scale. One paper proves that there exists a deterministic algorithm for stochastic online sorting with expected cost
9
and also proves an $1$0 lower bound for any possibly randomized algorithm, showing that the upper bound is nearly optimal (Hu, 11 Aug 2025). The same paper gives a non-recursive algorithm with $1$1 cost with high probability (Hu, 11 Aug 2025).
Another paper gives an $1$2-competitive algorithm for the stochastic online sorting problem that succeeds with high probability, improving exponentially over the earlier $1$3 bound. Its method is phased array partitioning into subarrays and buckets with dynamic capacity adjustment, analyzed through a balls-into-bins process controlled by Chernoff bounds and a union bound (Fotakis et al., 17 Aug 2025). That approach extends to any known input distribution by partitioning $1$4 into intervals of equal probability mass, and also extends to the stochastic online TSP in fixed dimension $1$5, again with $1$6-competitive ratio (Fotakis et al., 17 Aug 2025). A closely related 2025 paper obtains the same $1$7 competitive ratio for stochastic online sorting and stochastic online TSP through a hierarchy of balls-into-bins instances (Kalavas et al., 30 Sep 2025).
The adversarial multidimensional problem is harder. For points in $1$8, an online TSP interpretation uses cost
$1$9
and a deterministic algorithm achieves competitive ratio 0 for fixed 1 (Abrahamsen et al., 2024). The one-dimensional lower bound still gives 2 in this setting (Abrahamsen et al., 2024). Thus the stochastic model admits polylogarithmic ratios, while adversarial high-dimensional input remains at 3 scale.
6. Progressive, anytime, and application-specific uses of “online sorting”
A separate line of work studies online sorting via search and selection queries. Starting from an unsorted array, the algorithm answers online rank-selection and value-search queries while progressively sorting the list. The key data structure is a bit vector 4 marking positions already known to contain pivots in their final sorted locations. With the last item as pivot, 5 unique selection and search queries can be answered in total 6 average time; with median-of-medians or randomized pivots, the same total bound becomes deterministic worst-case or expected time, respectively. Repeated selection queries take constant time, repeated search queries take 7, and after 8 queries the list is sorted (0907.1295).
The anytime sorting problem is different again. Here comparisons are treated as steps, and the objective is to provide tentative estimates of the sorted list at each execution step. Estimation accuracy is measured by Spearman’s footrule
9
The paper introducing the anytime formulation proposes a general approach for making any sorting algorithm anytime and presents two new algorithms, multizip sort and Corsort. Simulations show superior performance of both algorithms compared to existing methods; multizip sort keeps a low global complexity, while Corsort produces intermediate estimates surpassing previous algorithms (Caizergues et al., 2024).
The phrase “online sorting” also appears in domain-specific literatures that do not study the same formal optimization problem. In brain-computer interfaces, “online spike sorting” refers to real-time separation and classification of neural spike activity. Ada-SpikeDeepClassifier is an adaptive, self-organized, self-supervised pipeline using SpikeDeeptector for channel selection, Ada-BAR for background-activity rejection, and an adaptive spike classifier for neural-unit classification; it is described as the first spike sorting algorithm that automatically learns abrupt changes in the distribution of noise and spike activity (Saif-ur-Rehman et al., 2023). In online deliberation platforms, the issue is not numerical sorting but principled ordering of proposals by content, user evaluation, and metadata; work in this area criticizes sorting solely by approvals and argues for integrated, proportional, or coverage-based methods (Janssens et al., 26 Feb 2026). A neighboring scheduling formulation, the offline sorting buffer problem, is strongly NP-hard; it nevertheless admits a linear-time dynamic programming algorithm for buffer size two and an 00-approximation with buffer size 01 (Chan et al., 2010).
Taken together, these lines of work show that “online sorting” names a broad research area rather than a single problem. In comparison-based models, the decisive quantities are entropy and stability; in array-placement models, they are competitive ratio, slack space, and stochastic structure; in progressive and anytime models, they are cumulative query complexity and intermediate ranking quality. The most active current frontier is the array-placement problem, where recent results have reduced long-standing gaps in the slack-space and stochastic regimes to polylogarithmic or nearly polylogarithmic factors (Azar et al., 19 Aug 2025, Hu, 11 Aug 2025, Fotakis et al., 17 Aug 2025).