Manuscript Offprint
arXiv:2610.39105Building On Learning-Augmented Online Sorting
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Online sorting is a problem that has gained attention recently, and is a natural translation of sorting into an online setting. The problem at hand is to place elements of an online sequence immediately and irrevocably with the goal of producing an array that is as close to sorted as possible upon inserting all elements. Recent work by Bercea et al. [3] introduced the incorporation of learned predictions into the online sorting domain. They show lower bounds for the consistency and robustness of any algorithm, including randomization, then provide a deterministic algorithm that is -consistent and -robust, which are tight bounds. However, this algorithm requires prior knowledge of the optimal offline cost of the full input sequence before all elements have been revealed. We resolve this by providing an algorithm with matching bounds that does not require knowledge of the optimal cost, then extend these results to the more general problem of online metric TSP, in line with the prior work.
1 Introduction
A small but interesting line of work has recently arisen surrounding the problem of online sorting, which was first proposed by Aamand et al. [1] in work exploring translation-only polygon packing in an online setting. The problem is as follows: we are given an online input sequence to be sorted into an array of length such that an element of the input sequence must be irrevocably placed into an empty cell of before the next element of the sequence appears. The goal is for to be as close to sorted as possible upon assigning all values of to cells in . The cost of the resulting array provides a measure to quantify this closeness and is defined as . It is clear that the optimal cost is given when is sorted in the traditional sense, in which case the cost is simply the range of the elements of (i.e. ).
With the introduction of predictions to an algorithm, we utilize two distinct metrics to analyze the cost in place of competitiveness. We say that an algorithm is -consistent if for all instances of the problem we are guaranteed a cost at most , where is the cost of an algorithm that simply follows the provided predictions. Following convention, we also say that an algorithm is -robust if for all instances of the problem we are guaranteed -competitiveness, regardless of predictions and predicted cost. Intuitively, robustness ensures bad predictions don't result in excessively poor cost, while consistency ensures that to some degree, we are able to reap the rewards of good predictions. For online sorting, Bercea et al. [3] provide tight bounds for both metrics: -robustness and -consistency for (the lower bound tightens this to ), which includes randomized algorithms. Of interest to us, they provide a deterministic algorithm that meets these bounds for online sorting; however, it requires prior knowledge of the optimal offline cost to meet these bounds. Our contribution is an algorithm inspired by this work that meets the same bounds without knowledge of the optimal cost.
Another contribution of Bercea et al. is providing an asymptotically tight learning-augmented algorithm for a more generalized version of online sorting, which was presented in [2] as the online TSP problem. The bounds for this general setting match those of sorting, and the algorithmic approaches are nearly identical from the perspective of algorithms utilizing predictions. One appropriate distinction to make in this problem is replacing our prior -competitive solution with the clever algorithm devised by Bertram in [4] that handles the complications involved with distances in higher-dimensional metric spaces to match the -competitive algorithm for online sorting. Again, the algorithm presented in [3] has the downside of requiring knowledge of the optimal cost of the input sequence. Similar to the prior work, we are able to treat the -competitive algorithms for the respective problems effectively as black boxes, so our approach for online sorting can be transferred neatly to this general space, matching the prior work's bounds without prior knowledge of the optimal cost.
1.2 Contributions
In this work we provide a pair of algorithms that match the cost bounds of those given by Bercea et al. [3] for both online sorting and online metric TSP without requiring knowledge of the optimal solution to ensure those bounds. We choose to separate these two cases despite the latter being a generalization of the former because online sorting provides a much more natural space to work in, allowing us to build intuition that eases the understanding of online metric TSP.
2 Online Sorting With Predictions
Here we present an alternative algorithm to that given by [3] that does not require knowledge of the optimal cost to achieve both -consistency and -robustness. Similar to this prior work, it utilizes a block structure and the deterministic -competitive algorithm presented in [2] that is oblivious to predictions as a sub-routine; however, we run an independent instance of this algorithm within each block with a coarser block width, preventing the need for a second phase or monitoring the cost with respect to the optimal.
2.1 Defining the Algorithm
Let be a parameter , following from prior work [3]. We break up the target array into contiguous blocks of size , where the -th block consists of the -st cell to the -th cell. Following [3], to simplify notation we assume without loss of generality that and are integers. Let be our input sequence to be sorted and be the sequence of predictions such that at time , item would be inserted at if we were to simply follow the sequence of predictions.
Our algorithm is simple when abstracting the online sorting algorithm from [2]; let us refer to it as . For each block, create a new instance of that will run on the sequence of items we assign to the given block. Then, for each input , identify the block corresponding to its predicted index; that is, find such that . Hand off to the instance of corresponding to that will in turn place within . We note here that we are guaranteed each block receives precisely the number of elements it needs because the predictions are a permutation of the indices of .
2.2 Cost Analysis
We now analyze the cost of the solution of this algorithm, aiming to show that it is -consistent and -robust. We first reiterate a fact shown in [3], referenced there as Claim 6.
Proposition 2.1 (Adapted from Bercea et al. [3], Claim 6). Let A be an array partitioned into k blocks . Then the predicted cost of the sequence satisfies
Intuitively, this states that the minimum cost of each block is realized when it is sorted, that cost being its range. So, the cost of the algorithm with predictions must have a cost of that is at least the cost of the sum over all blocks of the range within each block.
Claim 2.2. Our proposed algorithm is -consistent.
Proof. We incur costs in two distinct ways: costs within blocks and costs between the edge elements of consecutive blocks.
First, consider the cost within each block. Since the optimal cost for each block is and each block has elements, the cost of the block is at most where is the constant hidden in the asymptotics from . Then, the cumulative cost over all blocks is . By the first inequality in Proposition 2.1, we see that this value is upper bounded by .
Next, consider the cost between consecutive blocks. For a single pair of blocks, this value is the difference between the right-most value of the left block and the left-most value of the right block. At worst, this value is the difference between the maximum and minimum value across both sets, or . Considering all consecutive pairs of blocks, we get a cost of at most . By the second inequality in Proposition 2.1, we know this value is in turn at most .
Combining the two distinct types of costs, we see that this algorithm has a cost of at most
Thus, the algorithm is -consistent.
Claim 2.3. Our proposed algorithm is -robust.
Proof. Again, consider the costs within each block first. By our use of , we know the cost of any block is at most , where is the optimal cost for the given block. It is easy to see that . The cost across all blocks is then at most .
Considering the cost between pairs of consecutive blocks, we know that the maximum cost between two elements is . So, the cost for all consecutive pairs in adjacent blocks is at most . Since , we can see , and in turn . Then the cost between consecutive blocks is at most .
Once again, combining the two distinct types of costs, we see that this algorithm has a cost of at most
Thus, the algorithm is -robust.
3 Online Metric TSP With Predictions
The online sorting problem is a special case of the online traveling salesman problem (online TSP) on the line metric [2, 3]. In the general setting, the input sequence is drawn from an arbitrary metric space , and the cost of an array is defined as .
Our algorithm from Section 2 extends directly to general metric spaces without knowing . We maintain an identical block partition of width and routing rule based on , and simply replace inside each block with the deterministic -competitive algorithm for online metric TSP by Bertram [4], which we denote as . Like , does not require prior knowledge of the optimal cost and does not deal with predictions.
3.1 Cost Analysis
To adapt the analysis of Section 2 to a general metric , let denote the array formed by following the predictions directly, and for any block , let and denote the predicted cost and the optimal TSP cost, respectively, restricted to the elements assigned to . Finally, let denote the diameter of a subset of elements . We use the metric analog of Proposition 2.1 from [3].
Proposition 3.1 (Adapted from Bercea et al. [3], Claim 17). Let A be an array partitioned into k blocks . Then the predicted cost satisfies
Claim 3.2. For any , the proposed algorithm for online metric TSP with predictions is -consistent and -robust without knowledge of .
Proof. Because the block sizes and block count are identical to Section 2, it suffices to show that the intra-block and inter-block metric costs obey the same upper bounds used in Claims 2.2 and 2.3.
For consistency, running on block guarantees a cost within the block of at most . Because is a valid ordering of the exact multiset of elements assigned to , its cost is at least the optimal cost on those elements, so . Summing over all blocks and applying the first inequality of Proposition 3.1 gives
Furthermore, the distance between the adjacent boundary elements of and is at most , which sums to at most across all boundaries by the second inequality of Proposition 3.1. The remainder of the consistency bound follows identically to Claim 2.2.
For robustness, observe that by the triangle inequality, shortcutting the globally optimal tour past all elements not in cannot increase its cost, which implies . Likewise, the distance between any pair of boundary elements in adjacent blocks is at most . Substituting these two bounds into the proof of Claim 2.3 immediately yields a total cost of at most .
4 Closing Remarks
In this work we improve on prior algorithms that aim to leverage learned predictions in the setting of online sorting and its generalization to online metric TSP. Specifically, we provide an algorithm for each, inspired heavily by previous work, that relieves the constraint of knowing the optimal cost before all elements of the online input have been revealed.
We leave open questions that reiterate those of prior work. In particular, we are interested in predictions that need not produce a permutation of the input. A seemingly significant question is whether we can achieve the same bounds when there are collisions in the predictions. Can we handle such collisions in an efficient way?
References
[1] Anders Aamand, Mikkel Abrahamsen, Lorenzo Beretta, and Linda Kleist. Online sorting and translational packing of convex polygons. In Proceedings of the 2023 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1806–1833. SIAM, 2023.
[2] Mikkel Abrahamsen, Ioana O Bercea, Lorenzo Beretta, Jonas Klausen, and László Kozma. Online sorting and online tsp: randomized, stochastic, and high-dimensional. arXiv preprint arXiv:2406.19257, 2024.
[3] Ioana O. Bercea, Gerth Stølting Brodal, John Iacono, László Kozma, and Debmalya Panigrahi. Learning-augmented online sorting and TSP. In 34th Annual European Symposium on Algorithms (ESA 2026), 2026.
[4] Christian Bertram. Online metric tsp. arXiv preprint arXiv:2504.17716, 2025.