Sorting with Predictions

Xingjian Bai, Christian Coester

Introduction

Sorting is a fundamental operation in computer science, traditionally governed by the $\Omega(n \log n)$ lower bound for comparison-based algorithms. However, this theoretical floor assumes a "start-from-scratch" scenario where no prior information about the data exists. In practice, we often possess auxiliary information—such as historical rankings, outdated datasets, or fast but noisy proxies—that can provide a head start. This paper introduces a suite of "learning-augmented" sorting algorithms designed to leverage these potentially erroneous predictions to break the $O(n \log n)$ barrier.

The Learning-Augmented Framework

The authors define three critical properties for any learning-augmented algorithm:

  1. Consistency: The algorithm should achieve near-linear $O(n)$ performance when predictions are perfectly accurate.
  2. Robustness: In the worst-case scenario where predictions are entirely wrong, the algorithm must not perform significantly worse than classical $O(n \log n)$ sorting.
  3. Smoothness: The performance should degrade gracefully as the error in the predictions increases, rather than failing catastrophically at a specific error threshold.

Proposed Methodologies

The paper explores two primary settings for predictions: positional hints and "dirty" comparisons.

1. Sorting with Dirty Comparisons

In many domains, such as biological testing, one might have access to a "dirty" comparator (a fast, cheap, but potentially incorrect test) and a "clean" comparator (a slow, expensive, but exact test). The proposed algorithm utilizes a randomized Binary Search Tree (BST) approach. It performs a "dirty search" to identify a candidate position for an item, followed by a verification phase to backtrack to the last valid node, and finally a "clean search" to finalize the insertion. This minimizes the use of expensive clean comparisons.

2. Displacement Sort (Positional Predictions)

When each item is accompanied by a predicted rank, the Displacement Sort first bucket-sorts items based on these predictions. It then inserts them into a finger tree—a specialized balanced BST that optimizes insertions near the last accessed element. This structure allows the algorithm to capitalize on the proximity of the predicted rank to the actual rank.

3. Double-Hoover Sort (One-sided Positional Predictions)

Designed for cases where prediction errors are "one-sided" (e.g., an item is consistently predicted to be further left than its true position), the Double-Hoover Sort maintains two sorted structures. It employs a "strength-based" insertion scheme, metaphorically "hoovering" items into the correct list as the search range (suction power) expands over successive rounds.

Theoretical Contributions

A key insight of this work is the shift from global disorder metrics to element-wise error bounds. The authors prove that their algorithms achieve a complexity of $O(\sum \log (\eta_i + 2))$, where $\eta_i$ represents the error for an individual element. This ensures that a few highly inaccurate predictions do not compromise the efficiency gained from the correctly predicted majority. Furthermore, the authors demonstrate that this complexity is theoretically optimal, matching the entropy of the error distribution.

Empirical Evaluation

The algorithms were tested against synthetic benchmarks and real-world data:

  • Synthetic Settings: In the "Class" setting (where items are grouped into coarse grades), Displacement Sort and Double-Hoover Sort outperformed established baselines like TimSort and QuickSort once the number of classes exceeded 5% of the total items.
  • Real-World Data: Using World Bank population rankings (1960–2010), the authors used historical data as a "prediction" for future rankings. Displacement Sort proved fastest for short-term predictions (within 5 years), while Double-Hoover Sort dominated for noisier, long-term predictions (up to 60 years old).
  • Performance Smoothness: Experiments confirmed that as the "gap in years" (the error) increased, the number of comparisons grew predictably and slowly, validating the smoothness property.

Discussion and Future Work

While these algorithms are optimal in terms of comparison complexity, there are practical trade-offs. The Double-Hoover Sort, for instance, involves management overhead for its dual sorted structures that may impact total wall-clock time. Similarly, the dirty comparison algorithm is most beneficial when the cost differential between clean and dirty comparisons is high.

Future research directions include the development of algorithms that can actively learn or refine predictors during the sorting process itself, potentially removing the requirement for pre-existing external hints.

Summary updated

BibTeX
@inproceedings{bai2023sorting,
  author = {Xingjian Bai and Christian Coester},
  title = {{Sorting with Predictions}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=Qv7rWR9JWa},
}
Figure