Manuscript Offprint
arXiv:2611.08397A Near-Optimal Generalized Sorting Algorithm
Abstract
We continue the study of the classic generalized sorting problem, a basic variant of ordinary sorting. There are elements and an (initially hidden) total ordering over them. Unlike in ordinary sorting, however, only some comparisons are allowed: those given by the edges of an undirected graph on the elements. How many comparisons are needed to find the total ordering?
In ordinary sorting, comparisons are necessary and sufficient. For generalized sorting, however, the best known upper bound has been since the work of Huang, Kannan, and Khanna (FOCS 2011), who even asked whether the problem might in fact require comparisons. We show that it does not: we give a randomized algorithm that uses 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
Generalized sorting is the special case of sorting with priced comparisons in which every comparison costs either 1 or . Charikar et al. [CFG] initiated the study of query strategies for priced information and observed that sorting with priced comparisons appears highly non-trivial. Subsequent work studied sorting and selection when comparison costs are structured, e.g., monotone or metric [GK01,KK03,GK05], or random [AKM08]. Variants of generalized sorting, however, date back several decades. For instance, when , this is the ordinary sorting problem, for which a myriad of algorithms and lower bounds establish that comparisons are necessary and sufficient. When is instead the complete bipartite graph , this recovers the famous “sorting nuts and bolts” problem, where only elements on different sides of the bipartition can be compared (nuts cannot be compared with nuts, nor bolts with bolts). Through a sequence of works from the 1990s [ABF,ABF96,KMS98], a tight deterministic bound of queries was ultimately established for this problem as well. These works rely crucially on the complete bipartite structure of the comparison graph.
In many natural settings, however, the comparison graph has no such structure. As a motivating example from [HKK11], consider several candidates applying for the same job, together with a set of references for these candidates. Two candidates are comparable if some reference knows both of them. Clearly then, there is no guarantee that every pair of candidates is comparable.
As observed by Huang, Kannan, and Khanna [HKK11], the standard approaches to sorting break down when only some comparisons are allowed. For instance, a QuickSort-style algorithm needs a pivot that can be compared with most other elements, but an arbitrary graph may have no such pivot. Similarly, a MergeSort-style algorithm splits the elements into subproblems and sorts each of them recursively. This also breaks down in our setting for a subtle reason, which is that a subproblem may not be sortable on its own. Indeed, when we arbitrarily restrict to smaller subproblems, elements that are consecutive within a subproblem need not be comparable.
More generally, algorithms for ordinary sorting implicitly rely on the fact that at every stage, some comparison is balanced: whichever way it is answered, it eliminates a constant fraction of the orderings that are still consistent with the answers so far. Making such a comparison at every step sorts the elements using comparisons. In contrast, when comparisons are restricted, there may be intermediate stages at which no allowed comparison is balanced, which makes generalized sorting considerably more challenging.
As a result, progress on generalized sorting for arbitrary graphs has been slow. For a decade after [CFG], no -query algorithm was known, until Huang, Kannan, and Khanna [HKK11] showed that generalized sorting is possible with queries. Subsequent works extended [HKK11] in several directions, but none improved the bound for arbitrary graphs, which has stood since 2011. For instance, Kuszmaul and Narayanan [KN22] showed that when has edges, generalized sorting can be done with queries; however, when , this provides no improvement over [HKK11]. They also showed that when is an Erdős-Renyi random
An randomized algorithm is easy to obtain for this setting via a QuickSort style partitioning scheme.
graph (with the promised Hamiltonian path added), generalized sorting can be done with queries in expectation.
In a different direction, Lu, Ren, Sun, and Zhang [LRSZ20] studied generalized sorting with predictions, where one is given a prediction function that predicts the orientation of every edge of . When makes only errors, [LRSZ20] shows that generalized sorting can be done in queries. The difficulty of the general problem has also motivated the study of special cases of generalized sorting on structured graphs [BR16, BJR17, CSW23, JWZZ23, GJ22, GJ23], but an -query algorithm for general graphs has remained elusive.
Taken together, these results leave open the central question in the study of generalized sorting. The only known lower bound is the same bound from ordinary sorting. In fact, motivated by the lack of progress, Huang, Kannan, and Khanna [HKK11] even asked whether it can be strengthened to for some constant . In this work, we address the following question:
Is generalized sorting on arbitrary graphs polynomially harder than ordinary sorting? Can one perform generalized sorting in queries, or even in queries?
1.1 Our Main Result
Our main result nearly settles this question: we show that the query complexity of generalized sorting matches that of ordinary sorting up to polylogarithmic factors. Our main theorem is the following:
Theorem 1.1. There is a randomized algorithm that, for every graph on vertices and every hidden ordering of such that for all , recovers using queries in expectation.
In particular, Theorem 1.1 answers the question of [HKK11]: generalized sorting is not polynomially harder than ordinary sorting. Perhaps surprisingly, despite the long history of the problem, our algorithm turns out to be relatively simple.
A Brief Overview of Techniques Our starting point is the prediction-repair algorithm of [LRSZ20]. Indeed, as mentioned above, [LRSZ20] shows that, given a prediction function (which predicts an orientation for every edge in ) that makes only errors, one can perform generalized sorting in only many comparisons. This already suggests a natural starting point: can one show that in only queries, one can construct a predictor which makes only errors?
Our main result is an algorithm which exactly achieves this above goal, though the actual construction of the predictor may be slightly counterintuitive. To describe this, we begin with the key lemma which underlies the construction of this predictor:
Lemma 1.2. For any subset of edges , there is a randomized procedure that partitions into a “removed” set and the edges , along with predictions for these latter edges, such that:
-
.
-
The expected number of incorrect predictions on is .
-
The total number of queries made is .
Moreover, the procedure does not require to contain a Hamiltonian path.
It is worth making several remarks on the above lemma. First, it works for an arbitrary subset of the original edges in the graph , even if the chosen set of edges does not contain a Hamiltonian path. Beyond this, it produces a good prediction of edge orientations (with only expected errors) for most of the edges in the set . For some edges (those in the “removed set” ), it will neglect to produce a prediction, and defers the prediction for such edges until future rounds.
With the above lemma in hand, it is not hard to see how we produce the final predictor. We start with the entire edge set, i.e., , and apply the above lemma. This makes queries, and produces a prediction over at least half of the edges in which makes only errors. The set still has no predictions made, so we then repeat the above lemma with the choice , and so on.
The key subtlety emerges in proving this lemma, which follows a type of “prediction refinement” procedure. In more detail, given the edge set , we start by sampling a “coarse prediction” of the orientations of edges in . This coarse prediction is not very accurate and makes many errors, say, on the order of . There are then two ways that one could hope to decrease the number of errors:
-
We can try to update the prediction to be better on its mispredicted edges.
-
Or, we can try to locate regions of the graph where the mispredictions are denser than average, and remove these.
Our approach only tries to implement the second objective above, repeatedly removing regions with dense errors, and in so doing, driving down the error rate in the remaining edges. This takes the form of an iterative algorithm where in the th round, we identify a batch of roughly many edges, such that, after removing these edges, the number of remaining mispredictions decreases by a factor of . One can then see that across rounds of this procedure, the number of mispredictions decreases to , while the number of removed edges scales as .
Of course, this still leaves the task of designing this single round procedure, which we dub the error isolation protocol. To simplify the exposition here, we suppose that we are working with a bipartite graph, where the prediction guesses that all edges go from to . Roughly speaking, this protocol then operates by randomly sampling a set of mispredicted edges (edges that point from right to left), and storing the right hand vertices of every sampled edge in a set . It then queries all of the edges to the left neighbors of these vertices in . Ultimately, the procedure must produce a collection of edges which has disproportionately many errors, and it does this in two ways:
-
When querying the left neighbors of each , if an edge is mispredicted, we remove all of 's edges.
-
Then, we choose a permutation over the vertices . For each , we compute its score to be the smallest rank (in ) of any of 's neighbors in (if there are no neighbors, we give it rank ). For every , we then remove all edges to 's highest scoring neighbors.
The first condition above has a very intuitive interpretation, as it simply captures that a left vertex may have a “high density” of errors among its sampled incident edges. The second condition is less intuitive; but is roughly designed with the goal of capturing errors that are not observed in our random sampling. This is because if a left vertex has a high score, then none of the sampled vertices appearing early in are neighbors of this left vertex. It turns out that this provides a valuable signal that we should suspect that our random sampling is not as accurate for this vertex.
Surprisingly, the heart of the analysis in Section 3.4 shows that there exists a choice of this permutation over for which the edge removal procedure above succeeds in reducing the number of remaining errors by a factor of 2. Of course, there still remain many details in the procedure, including: (a) how do we find this optimal choice of ? (b) how do we ensure that not too many queries are made? (c) how do we locate the mispredicted edges? and so on. We defer these complete descriptions to the (brief) technical sections below, but nevertheless, this discussion above captures the overarching structure of our algorithm.
1.2 Future Directions
We highlight three natural directions for future work.
-
Closing the remaining gap. Our algorithm uses queries, an factor more than the lower bound for ordinary sorting. Can generalized sorting be done with queries on every graph, or do some graphs require queries?
-
Deterministic algorithms. Similar to previous algorithms for sorting on arbitrary graphs [HKK11,KN22], our algorithm is randomized. What is the deterministic query complexity of generalized sorting? In particular, is there a deterministic algorithm that uses queries? Even for nuts and bolts, where a simple randomized variant of QuickSort uses comparisons in expectation, matching this bound deterministically took a sequence of works [ABF+94,ABF96,KMS98].
-
Polynomial-time algorithms. We focus on query complexity, and as stated, our algorithm does not run in polynomial time. Is there a polynomial-time algorithm that uses queries, or even queries? For comparison, the -query algorithm of [HKK11] runs in polynomial time.
2 Overview
We begin by defining the distance between two orderings or predictions.
Definition 2.1. For a graph , two total orderings over , and a subset of edges , we define
Likewise, we extend this definition to prediction functions, which map every edge to an orientation or . For such a function , we define
We write and .
Our algorithm has two main components. The first, which is our main contribution, constructs a prediction function with expected errors using queries. The second, due to [LRSZ20], recovers the hidden ordering from a prediction function with errors using queries. We describe these components below.
Prediction construction. Our algorithm proceeds in phases. In each phase, it fixes predictions on a subset of edges and postpones the remaining edges to subsequent phases. The progress made in each phase is summarized by the following lemma.
Lemma 2.2. Let be an undirected graph with a hidden total ordering over its vertices. For any subset of edges , there is a randomized algorithm that makes comparisons and partitions into a postponed set and a set of predicted edges such that and the expected number of incorrect predictions on is at most .
By repeatedly applying the lemma to the postponed edges, the number of unresolved edges decreases by half in each phase. Therefore, after phases, all edges in are predicted. Combining these predictions yields a prediction function with many expected errors, using comparisons in total.
Prediction repair. After obtaining a prediction function with few errors, we apply the prediction repair algorithm due to [LRSZ20]. We remark that this is the only step that requires the graph to contain the Hamiltonian path induced by the hidden total order .
Lemma 2.3 ([LRSZ20]). Let be an undirected graph on vertices and edges with a hidden total ordering over its vertices such that all consecutive vertices in are adjacent in . Suppose there is a prediction function over the edges of such that
Then there is a randomized algorithm that, given and , makes at most queries in expectation and recovers the true ordering .
Combining the prediction construction and repair algorithms proves Theorem 1.1. The remainder of the paper is devoted to proving Lemma 2.2.
3 Repeated Error Isolation for Near-Optimal Generalized Sorting
In this section, we describe our prediction construction algorithm in detail. The key idea underlying our algorithm is to iteratively refine a prediction of edge orientations by gradually removing sets of edges that are “denser” with errors than the remaining edges. Throughout this section, we suppose that we are working with a set of edges from the original generalized sorting instance. We begin by describing a procedure that produces a coarse prediction of the orientations of the edges in .
3.1 Building a Coarse Predictor
In this section, we describe the coarse prediction routine, which uses queries to construct a prediction for with errors. If , we simply query all edges in and terminate. Otherwise, we sample edges uniformly at random from (with replacement), and then let be any permutation of the vertices which agrees with the reported orientation of every sampled edge. Note that such a permutation must exist, since the true permutation agrees with all reported orientations. For this permutation , we have the following claim:
Claim 3.1. With probability over the random sample, it is the case that
Proof. Fix any permutation with . A uniformly random edge of that we sample has probability at least of disagreeing with orientation . Thus, the probability that remains consistent with sampled edges (and therefore could be returned as the coarse predictor) is at most
Taking a union bound over all ! possible choices of , we obtain
which yields the desired claim.
For the rest of this section, we condition on the good event that .
3.2 Building a Bounded-Degree Bipartite Prediction Graph
We next transform into a bipartite graph with maximum degree , which will be useful in our algorithm and analysis.
To start, we duplicate the vertex set , creating a left copy and a right copy . For every edge with , we add an edge between the copy of in and the copy of in . Thus, predicts every edge to be oriented from to .
Next, let denote the average degree of the bipartite graph. If any left or right vertex has more than d incident edges, we split the edges into groups of size at most d, making a separate copy of the vertex for each group. We denote the final resulting bipartite graph from this procedure by . We have the following claims about this graph:
Claim 3.2. Let H be constructed as above. Then, all of the following hold:
-
Every vertex in H has degree at most d.
-
There are at most 2n left vertices and 2n right vertices.
-
and .
Proof. The first item is immediate. To see the second item, observe that the number of left vertices is bounded by , and similarly for right vertices. For the third item, it follows from our assumption that and the definition of .
3.3 Removing Right Vertices with Too Many Errors
In the bipartite graph , we say that an edge with is a bad edge if if its orientation is incorrectly predicted by , i.e., . Let be the total number of bad edges. The next step of our algorithm identifies and removes right vertices that are incident to too many bad edges.
To do this, we take a new uniformly random sample of many edges from , and query their true orientations. We flag a vertex if at least sampled edges incident to are bad. We have the following claim about flagged vertices:
Claim 3.3. With probability , the following hold:
-
Every flagged vertex is incident to at least bad edges.
-
Every unflagged vertex is incident to most bad edges.
Proof. Fix a right vertex with many bad incident edges. The number of bad edges incident to in the sample is then exactly distributed as a binomial random variable with mean
If , then . If , then . Since the threshold is , by standard Chernoff bounds, vertices in the first case are unflagged with probability , and vertices in the second case are flagged with probability . By taking a union bound over all vertices, we then obtain the stated claim.
We now remove all edges incident to flagged vertices from . The following claim bounds the number of removed edges.
Claim 3.4. Assuming the good events in Claim 3.1 and Claim 3.3, the number of removed edges is at most .
Proof. By Claim 3.1, we know that the total number of bad edges is bounded by . At the same time, by Claim 3.3, every flagged vertex has at least many distinct bad edges incident to it. Thus, the number of flagged vertices is at most
As every vertex has degree at most , removing all edges incident to flagged vertices deletes at most edges.
3.4 The Error Isolation Protocol
In this section, we describe the error isolation protocol. We use positive integers and as parameters of our protocol, and use to denote the number of bad edges (errors) in the current graph under consideration. The steps of the protocol are:
-
We first sample uniformly random bad edges (with replacement), by repeatedly querying uniformly random edges of until a bad edge is found. For each bad edge, we store its right endpoint in a (multi)set . Thus, at the termination of this step, .
-
For every vertex , we query all edges of incident to . For any left vertex where we discover an incorrectly oriented edge (that is, ), we say that is a marked vertex.
-
Fix an arbitrary permutation over the sampled right vertices . For each left vertex , we define its score under as the minimum rank in over all of its neighbors in . I.e.,
If has no neighbors in , we simply define its score to be .
-
For every right vertex , we select its highest score left neighbors, breaking ties arbitrarily. Let denote the set of edges connecting to its selected neighbors.
-
Finally, let contain (1) all edges incident to a marked left vertex , and (2) for every , the edges going to its highest score left neighbors. I.e.,
As we will see in the following discussion, an appropriate choice of ensures that removing significantly reduces the number of bad edges. The key claim that we show is the following. Crucially, choosing such that ensures that removing reduces the number of remaining errors by a large constant factor.
Lemma 3.5. For each sampled multiset , let denote the ordering of vertices in induced by their relative order in the true permutation . Then, we have
Proof. We say a left vertex is late with respect to a right vertex if every sampled neighbor of comes after in the true permutation . For a right vertex , let denote the number of bad edges incident to , and let denote the number of its late neighbors.
First, observe that every bad edge with unmarked must have late with respect to . Indeed, since is unmarked, all of its sampled neighbors in come after in , while the bad edge implies that .
Moreover, under , every late neighbor of v has strictly higher score than every non-late neighbor. To see this, for any right vertex v, define
where are the vertices in . Thus, counts the number of sampled vertices coming at or before in the true order. Crucially, if is late with respect to , all sampled neighbors come after , and so . Otherwise, if is not late with respect to , some sampled neighbor of is at or before , and therefore , yielding the claim.
With these claims, we can see that if , then all bad edges with unmarked are removed in the set of the highest score vertices. This is because every such neighbor is late, and every late neighbor has a higher score than any non-late neighbor. Since there are at most late neighbors, all of them are among the with the highest scores. Therefore, after removing the highest score neighbors, the number of bad edges incident to with unmarked is at most
In particular, we can then bound the total number of such bad edges as
where is a random right vertex drawn from the same distribution as each sampled element of , namely .
Finally, it remains to bound . Fix any left vertex , and consider the independent samples consisting of and the vertices in . The event that is a late neighbor of requires to come before every sampled neighbor of in . Equivalently, among the samples that are neighbors of , must be the (unique) smallest in . As and the samples in come from the same distribution, this event has probability at most . Summing over all left vertices, we obtain
Plugging this into our earlier bound, we have that the expected (over our choice of ) number of remaining bad edges with unmarked is at most
Equivalently,
3.5 Invoking the Error Isolation Protocol
We now invoke the error isolation protocol. Throughout this section, we use H to denote the current graph, consisting of edges that have not yet been removed in Lemma 3.5.
We fix the parameters of the error isolation protocol as
Importantly, we see that which will allow us to conclude a significant reduction in the number of errors when applying Lemma 3.5. With these definitions, we are now ready to define a single pass of our error isolation procedure.
A Single Error Isolation Pass. We outline the procedure below. This procedure starts by sampling random edges, hoping to find enough bad edges to run the algorithm from Section 3.4. If not enough bad edges are found, we are already in a good case. Otherwise, if it finds enough bad edges, it carries out Section 3.4's protocol. It remains still to identify the permutation from Lemma 3.5. This is done by using an additional sample of bad edges to effectively “certify” whether any permutation behaves similarly to .
-
To start, we repeatedly sample uniformly random edges from and query their true orientations. The first bad edges found are called the training edges, and the subsequent bad edges are called the validation edges. Note that if we fail to obtain bad edges within many samples and queries, then we terminate prematurely. In the following steps, we assume the sampling succeeds.
-
Next, we perform the algorithm in Section 3.4 using the first bad edges (the training edges). Let be the multiset of right endpoints. We query all edges incident to vertices in , marking every left vertex incident to a queried bad edge. Then, for every ordering of , we construct the candidate removal set .
-
Finally, it remains to select one of the candidate removal sets. For this, we use the sample of bad, validation edges. We choose the candidate removal set that misses the fewest validation edges.
This completes the description of a single pass. We now analyze its properties and show that it successfully removes a large number of bad edges.
Analyzing a Single Pass. We first show that if at least n bad edges remain in H, then the sampling step succeeds with constant probability.
Claim 3.6. Suppose the current graph contains bad edges. Then, with probability at least 15/16, among the sample of edges, there will be bad edges.
Proof. Since contains at most edges and at least bad edges, the expected number of samples needed to collect bad edges is at most many edges. By a simple Markov bound, the probability that this takes more than queries is at most , proving the claim.
Next, we can observe that the bad edges collected by the sampling step are independent and uniformly distributed among the bad edges, and therefore is in line with the sampling procedure in Section 3.4. In particular, this allows us to immediately conclude the following:
Corollary 3.7. Let H be the current bipartite graph, and let denote the true relative order of the sampled multiset S. Then,
Note that here we have used the fact that , and that the number of left and right vertices in H is at most 2n.
However, the algorithm does not know true permutation , but instead choose the permutation for which misses the fewest validation edges. For this , we have the following claim:
Claim 3.8. Let denote the permutation whose candidate removal set misses the fewest of the validation edges. If the current graph contains bad edges, then after a single pass,
Proof. By Corollary 3.7, we know that there exists a permutation , for which misses a fraction of the validation edges in expectation.
Now, let us fix any candidate permutation . The fraction of the validation edges that are missed by is, in expectation, equal to the true fraction of bad edges missed by . We call this value the missing probability, and denote its estimate from the sampled validation edges by . By applying a standard Hoeffding bound,
Taking a union bound over all candidate permutations, we obtain that the probability that for any is bounded by .
Now, conditioned on for every , we can see that for the selected permutation , we have
Note that if the bad case of Claim 3.6 occurs, or the bad case above, where for some , we can bound the expected fraction of missed bad edges by by 1.
Thus, in total, we can see that
We can now apply this repeatedly to reduce the number of bad edges to .
Lemma 3.9. Let be the current graph with at most edges, and let be the coarse prediction. We apply the single error isolation pass times, removing the selected edge removal set from in each iteration. After these iterations,
Proof. Indeed, by Claim 3.8, each iteration of the above procedure reduces the expected number of bad edges from to at most in expectation, provided that . Thus, we can unconditionally bound the expected number of remaining bad edges by .
In particular, after iterations, the expected number of remaining bad edges in H is at most
This is extremely valuable; after iterations, we have essentially “purified” our graph , getting rid of most of the bad edges. However, it remains to show that in the process of removing these candidate removal sets , we have not removed too many edges from . Indeed, a trivial way to purify would simply have been to remove all of its constituent edges. In the following, we bound the total number of edges removed by our algorithm.
Bounding the Number of Removed Edges. In this section, we will show the following:
Claim 3.10. Let initially contain edges. Then, with probability , the flagging step and the subsequent error isolation passes together remove at most edges.
Proof. We condition on the good events of Claim 3.1 and Claim 3.3. By Claim 3.3, every right vertex in always has at most incident bad edges. Thus, in a single iteration of the error isolation protocol, the sampled right vertices mark at most
many left vertices. In turn, each of these left vertices ends up removing their entire neighborhoods, leading to a total of
many removed edges. The remaining edges in each candidate removal set come from the highest scoring vertices incident to each right vertex. Because there are at most right vertices, and
, this constitutes at most many removed edges. Therefore, in each of the rounds, the total number of removed edges is at most
where we have used that , and that . Summing across all rounds, this implies that at most edges are removed by the error isolation procedure.
Finally, by including the edges removed in Claim 3.4, we obtain the stated bound. ☐
Bounding the Number of Queries Performed. The final piece of our analysis is to bound the number of queries performed in the above process. For this, we establish the following claim:
Claim 3.11. Across building the coarse estimator, the vertex flagging, and the log n rounds of error isolation, the total number of queries made is bounded by .
Proof. This follows by simple book-keeping. Building the coarse estimator requires queries by construction. The flagging procedure similarly performs queries.
In each of the rounds of error isolation, we sample many random edges and query them. We also query all edges incident to the sampled right vertices, which requires at most additional queries. Across all rounds, the error isolation procedure requires queries,
3.6 Concluding the Algorithm
Now we summarize the above and prove Lemma 2.2. We use the procedure described in this section. Lemma 3.9 bounds the expected number of incorrect predictions. Claim 3.10 bounds the number of removed edges, which are the postponed edges. Claim 3.11 provides the desired query bound. Finally, we can absorb the small failure probability into the expected number of incorrect predictions by observing that the number of incorrect predictions is always bounded by . Similarly, if the proposed set of edge removals is , we can instead remove no edges, and again absorb this as a small failure probability (again, using the absolute bound of at most incorrect predictions).
4 AI Disclosure
ChatGPT 6-Astra was essential in proving the improved bounds. In particular, ChatGPT proved an query algorithm for generalized sorting which combined the prediction-repair algorithm of [LRSZ20] with a subsampling algorithm to estimate the rank of each element in the graph. ChatGPT was then unable to refine or improve this result, and it stagnated at queries. The authors subsequently identified a way to further reduce the number of queries by relying on careful implications in the graph structure, and, after several refinements, achieved many queries.
ChatGPT 6-Astra Ultra/Pro and 6.1-Sol Ultra were then prompted dozens of times with these generalized sorting algorithms over the course of several weeks, tasked with finding an improvement. Several improvements were found, including first, an query algorithm, then an , and then an query algorithm, before eventually discovering the query algorithm presented here. In full disclosure, although these models were given the query algorithm developed by the authors, it is not clear whether the tools developed therein were essential for discovering the ultimate query algorithm here. Indeed, the only shared pieces are merely high-level architectural choices like (a) doing efficient prediction-repair and (b) sampling vertices to estimate statistics of other vertices.
References
[ABF+94] Noga Alon, Manuel Blum, Amos Fiat, Sampath Kannan, Moni Naor, and Rafail Ostrovsky. Matching nuts and bolts. In Proceedings of the Fifth Annual SIAM Symposium on Discrete Algorithms, pages 690–696, 1994. 1, 4
[ABF96] Noga Alon, Phillip G Bradford, and Rudolf Fleischer. Matching nuts and bolts faster. Information processing letters, 59(3):123–127, 1996. 1, 4
[AKM08] Stanislav Angelov, Keshav Kunal, and Andrew McGregor. Sorting and selection with random costs. In LATIN 2008: Theoretical Informatics, 8th Latin American Symposium, volume 4957 of Lecture Notes in Computer Science, pages 48–59. Springer, 2008. 1
[BJR17] Arindam Biswas, Varunkumar Jayapaul, and Venkatesh Raman. Improved bounds for poset sorting in the forbidden-comparison regime. In Conference on Algorithms and Discrete Applied Mathematics, pages 50–59. Springer, 2017. 2
[BR16] Avah Banerjee and Dana Richards. Sorting under forbidden comparisons. 2016. 2
[CFG+00] Moses Charikar, Ronald Fagin, Venkatesan Guruswami, Jon Kleinberg, Prabhakar Raghavan, and Amit Sahai. Query strategies for priced information. In Proceedings of the thirty-second annual ACM symposium on Theory of computing, pages 582–591, 2000. 1
[CSW23] T-H Hubert Chan, Enze Sun, and Bo Wang. Generalized sorting with predictions revisited. In International Workshop on Frontiers in Algorithms, pages 29–41. Springer, 2023. 2
[GJ22] Mayank Goswami and Riko Jacob. On instance-optimal algorithms for a generalization of nuts and bolts and generalized sorting. arXiv preprint arXiv:2211.04601, 2022. 2
[GJ23] Mayank Goswami and Riko Jacob. An algorithm for bichromatic sorting with polylog competitive ratio. arXiv preprint arXiv:2311.05773, 2023. 2
[GK01] Anupam Gupta and Amit Kumar. Sorting and selection with structured costs. In 42nd Annual Symposium on Foundations of Computer Science, FOCS, pages 416–425. IEEE Computer Society, 2001. 1
[GK05] Anupam Gupta and Amit Kumar. Where's the winner? max-finding and sorting with metric costs. In Proceedings of APPROX-RANDOM 2005, volume 3624 of Lecture Notes in Computer Science, pages 74–85. Springer, 2005. 1
[HKK11] Zhiyi Huang, Sampath Kannan, and Sanjeev Khanna. Algorithms for the generalized sorting problem. In 2011 IEEE 52nd Annual Symposium on Foundations of Computer Science, pages 738–747. IEEE, 2011. 1, 2, 4
[JWZZ23] Shaofeng H-C Jiang, Wenqian Wang, Yubo Zhang, and Yuhao Zhang. Algorithms for the generalized poset sorting problem. arXiv preprint arXiv:2304.01623, 2023. 2
[KK03] Sampath Kannan and Sanjeev Khanna. Selection with monotone comparison cost. In Proceedings of the Fourteenth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 10–17. ACM/SIAM, 2003. 1
[KMS98] János Komlós, Yuan Ma, and Endre Szemerédi. Matching nuts and bolts in o (n log n) time. SIAM Journal on Discrete Mathematics, 11(3):347–372, 1998. 1, 4
[KN22] William Kuszmaul and Shyam Narayanan. Stochastic and worst-case generalized sorting revisited. In 2021 IEEE 62nd Annual Symposium on Foundations of Computer Science (FOCS), pages 1056–1067. IEEE, 2022. 1, 4
[LRSZ20] Pinyan Lu, Xuandi Ren, Enze Sun, and Yubo Zhang. Generalized sorting with predictions. arXiv preprint arXiv:2011.00172, 2020. 2, 4, 5, 12