Papers
Topics
Authors
Recent
Search
2000 character limit reached

Online Sorting Problem: Algorithms and Analysis

Updated 9 July 2026
  • 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 x1,,xn[0,1]x_1,\dots,x_n \in [0,1]. 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

cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,

where 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n are the filled indices in order; empty cells are ignored (Nirjhor et al., 20 Aug 2025). Closely related formulations consider an array of size nn with cost

CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|

(Abrahamsen et al., 2024), or define r0:=0r_0:=0 and rn+1:=1r_{n+1}:=1 and sum boundary terms as well (Aamand et al., 2021). In normalized inputs from [0,1][0,1] 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 SS of size cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,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 cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,1 of distinct elements and the entropy

cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,2

with all logarithms in base cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,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 cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,4 ternary comparisons when cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,5 (0907.0741)
Array-placement online sorting Place each arrival irrevocably into an array Adversarial competitive ratio cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,6 for size-cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,7 arrays (Abrahamsen et al., 2024)
Progressive or anytime sorting Refine order through queries or comparisons Total cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,8 for cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,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 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n0, then a multiset 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n1 can be sorted online and stably using at most 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n2 ternary comparisons, and in the worst case at least 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n3 ternary comparisons are required (0907.0741). The bounds are therefore tight up to 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n4.

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: 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n5 comparisons are sufficient and 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n6 are necessary. It also compares the online result with the best known offline upper bound 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n7, concluding that online stable sorting with ternary comparisons matches the best known offline upper bound up to an 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n8 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 1i1<<in(1+ε)n1 \le i_1 < \cdots < i_n \le (1+\varepsilon)n9, the strongest statement in the surveyed work is that the deterministic and randomized competitive ratio of online sorting is nn0, and the lower bound nn1 holds even for inputs from nn2 (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 OnlineSortingnn3, already isolated the same core phenomenon. For nn4, there exists an online algorithm with competitive ratio at most nn5, and every online algorithm has competitive ratio at least nn6 (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 OnlineSortingnn7, if a nn8-competitive algorithm exists, then nn9 (Aamand et al., 2021). For constant CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|0, this rules out constant competitiveness. In the exact-size case CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|1, the later CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|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 CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|3 for both deterministic and randomized algorithms, and with a larger array of size CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|4 the ratio becomes CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|5 (Abrahamsen et al., 2024).

4. Extra space, nearly tight tradeoffs, and structural algorithms

The most substantial recent progress concerns arrays larger than CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|6. Earlier work gave, for CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|7 with CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|8, a deterministic competitive ratio

CostA(X)=i=1n1A[i+1]A[i]\text{Cost}_A(X) = \sum_{i=1}^{n-1} |A[i+1]-A[i]|9

while the lower bound for r0:=0r_0:=00 was r0:=0r_0:=01 (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 r0:=0r_0:=02, it gives a deterministic r0:=0r_0:=03-competitive algorithm for any r0:=0r_0:=04. For r0:=0r_0:=05 where r0:=0r_0:=06, it gives a deterministic r0:=0r_0:=07-competitive algorithm (Azar et al., 19 Aug 2025). In particular, this implies an r0:=0r_0:=08-competitive algorithm with r0:=0r_0:=09 space, and yields an upper bound of rn+1:=1r_{n+1}:=10 on the product of competitive ratio and rn+1:=1r_{n+1}:=11, against the lower bound rn+1:=1r_{n+1}:=12 on the same product (Azar et al., 19 Aug 2025).

The algorithms in that work are tree-based. For rn+1:=1r_{n+1}:=13, 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 rn+1:=1r_{n+1}:=14 elementary trees. The analysis gives space rn+1:=1r_{n+1}:=15 and cost rn+1:=1r_{n+1}:=16, with rn+1:=1r_{n+1}:=17 yielding the stated competitive ratio (Azar et al., 19 Aug 2025). For rn+1:=1r_{n+1}:=18, the array is divided into rn+1:=1r_{n+1}:=19 composite trees covering disjoint subintervals of [0,1][0,1]0, and routing each arrival to the tree for its subinterval yields the [0,1][0,1]1 bound (Azar et al., 19 Aug 2025). The same paper also gives unknown-range variants via doubling, incurring an extra [0,1][0,1]2 factor (Azar et al., 19 Aug 2025).

An independent 2025 analysis obtains a deterministic quasi-polylogarithmic cost

[0,1][0,1]3

for the [0,1][0,1]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 [0,1][0,1]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 [0,1][0,1]6 are i.i.d. uniform on [0,1][0,1]7 and gives an online algorithm with competitive ratio [0,1][0,1]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

[0,1][0,1]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 SS0 for fixed SS1 (Abrahamsen et al., 2024). The one-dimensional lower bound still gives SS2 in this setting (Abrahamsen et al., 2024). Thus the stochastic model admits polylogarithmic ratios, while adversarial high-dimensional input remains at SS3 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 SS4 marking positions already known to contain pivots in their final sorted locations. With the last item as pivot, SS5 unique selection and search queries can be answered in total SS6 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 SS7, and after SS8 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

SS9

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 cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,00-approximation with buffer size cost(A)=k=1n1A[ik]A[ik+1],\operatorname{cost}(A) = \sum_{k=1}^{n-1} |A[i_k] - A[i_{k+1}]|,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).

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Online Sorting Problem.