arXiv:2611.08397cs.DSNov 2026

Manuscript Offprint

arXiv:2611.08397

A Near-Optimal Generalized Sorting Algorithm

Sanjeev Khanna, Aaron Putterman, Junkai Song

Abstract

We continue the study of the classic generalized sorting problem, a basic variant of ordinary sorting. There are nn elements and an (initially hidden) total ordering π\pi over them. Unlike in ordinary sorting, however, only some comparisons are allowed: those given by the edges of an undirected graph G=(V,E)G = (V, E) on the elements. How many comparisons are needed to find the total ordering?

In ordinary sorting, Θ(nlog⁡n)\Theta(n \log n) comparisons are necessary and sufficient. For generalized sorting, however, the best known upper bound has been O~(n3/2)\tilde{O}(n^{3/2}) since the work of Huang, Kannan, and Khanna (FOCS 2011), who even asked whether the problem might in fact require n1+Ω(1)n^{1+\Omega(1)} comparisons. We show that it does not: we give a randomized algorithm that uses O(nlog⁡4n)O(n \log^4 n) comparisons in expectation. Thus, up to logarithmic factors, generalized sorting is no harder than ordinary sorting.

*Courant Institute, New York University, New York, NY, USA. Supported in part by NSF award CCF-2625203 and AFOSR award FA9550-25-1-0107. Email: sanjeev.khanna@nyu.edu.

†School of Engineering and Applied Sciences, Harvard University, Cambridge, Massachusetts, USA. Supported in part by a Jane Street Graduate Research Fellowship, the Simons Investigator Awards of Madhu Sudan and Salil Vadhan and AFOSR award FA9550-25-1-0112. Email: aputterman@g.harvard.edu.

‡Courant Institute, New York University, New York, NY, USA. Supported in part by NSF award CCF-2625203. Email: junkaisong@nyu.edu.

Contents

1 Introduction 1 1.1 Our Main Result ..... 2 1.2 Future Directions ..... 4

2 Overview 4

3 Repeated Error Isolation for Near-Optimal Generalized Sorting 5 3.1 Building a Coarse Predictor ..... 5 3.2 Building a Bounded-Degree Bipartite Prediction Graph ..... 6 3.3 Removing Right Vertices with Too Many Errors ..... 6 3.4 The Error Isolation Protocol ..... 7 3.5 Invoking the Error Isolation Protocol ..... 9 3.6 Concluding the Algorithm ..... 12

4 AI Disclosure 12