Stochastic and Worst-Case Generalized Sorting Revisited
Abstract
The generalized sorting problem is a restricted version of standard comparison sorting where we wish to sort elements but only a subset of pairs are allowed to be compared. Formally, there is some known graph on the elements , and the goal is to determine the true order of the elements using as few comparisons as possible, where all comparisons must be edges in . We are promised that if the true ordering is for an unknown permutation of the vertices , then for all : this Hamiltonian path ensures that sorting is actually possible.
In this work, we improve the bounds for generalized sorting on both random graphs and worst-case graphs. For Erdős-Renyi random graphs (with the promised Hamiltonian path added to ensure sorting is possible), we provide an algorithm for generalized sorting with an expected comparisons, which we prove to be optimal for query complexity. This strongly improves over the best known algorithm of Huang, Kannan, and Khanna (FOCS 2011), which uses comparisons. For arbitrary graphs with vertices and edges (again with the promised Hamiltonian path), we provide an algorithm for generalized sorting with comparisons. This improves over the best known algorithm of Huang et al., which uses comparisons.
1 Introduction
Whereas the standard comparison-based sorting problem was solved more than half a century ago, several variations on the problem have only recently begun to be understood. One of the most natural of these is the so-called generalized sorting problem.
Generalized sorting: sorting with forbidden comparisons.
In the generalized sorting problem, we wish to sort the vertices of a graph, but only certain pairs of vertices are permitted to be compared. The input to the problem is a graph , where the vertices represent the elements to be sorted, and the edges indicate the pairs of vertices that can be compared; we will use to denote the true ordering of the vertices , and we say that if . The goal is to sort the vertices (i.e., discover the true ordering) with as few comparisons as possible. In this setting, comparisons are also referred to as edge queries, meaning that the goal is to achieve the minimum possible query complexity.
In order for an input to the generalized sorting problem to be valid, it is required that the true ordering of the vertices appears as a Hamiltonian path in . This ensures that, should an algorithm query every edge, the algorithm will be able to deduce the true order of the vertices.
A classic special case of the generalized sorting problem is the nuts-and-bolts problem, which considers the case where is a complete bipartite graph. The vertices on one side of the graph represent “nuts” and vertices on the other side of the graph represent “bolts”. The goal is to compare nuts to bolts in order to match up each nut with its correspondingly sized bolt. Nuts cannot be compared to other nuts and bolts cannot be compared to other bolts, which is why the graph has a complete bipartite structure. The problem was first introduced in 1994 by Alon et al. [1], who gave a deterministic -time algorithm. Subsequent work [2, 13, 6] improved the running time to , which is asymptotically optimal.
The first nontrivial bounds for the full generalized sorting problem were given by Huang et al. [11], who studied two versions of the problem:
-
•
Worst-case generalized sorting: In the worst-case version of the problem, is permitted to have an arbitrary structure. A priori, it is unclear whether it is even possible to achieve comparisons in this setting. The paper [11] showed that this is always possible, with a randomized algorithm achieving query complexity for any graph , with high probability.
-
•
Stochastic generalized sorting: In the stochastic version of the problem, every vertex pair (that is not part of the Hamiltonian path for the true order) is included independently and randomly with some probability . The paper [11] gave a randomized algorithm with query complexity, which evaluates to for the worst-case choice of .
Although there have been several subsequent papers on the topic [4, 14, 5] (which we will discuss further shortly), these upper bounds of and have remained the state of the art for the worst-case and stochastic generalized sorting problems, respectively. Moreover, no nontrivial lower bounds are known. Thus it is an open question how these problems compare to standard comparison-based sorting.
This paper.
The main result of this paper is an algorithm for stochastic generalized sorting with query complexity . This means that, in the worst case, the query complexity of stochastic generalized sorting is asymptotically the same as that of classical sorting. Perhaps even more remarkably, when is small, stochastic generalized sorting is actually easier than its classical counterpart; for example, when , the query complexity becomes .
When , which is the parameter regime in which the Erdös-Renyi random graph contains at least one Hamiltonian cycle with overwhelming probability, we prove a matching lower bound of for the query complexity of any stochastic-generalized-sorting algorithm. Thus our algorithm is optimal.
Given that the optimal running time for stochastic generalized sorting is faster for sparser graphs, a natural question is whether the running time for worst-case generalized sorting can also be improved in the sparse case. It is known that in the very dense case, where there are edges, there is an algorithm with query complexity [4]. However, in the case where there are edges, the state-of-the-art remains the bound of [11], where one can always get an -query bound simply by querying all edges.
Our second result is a new algorithm for worst-case generalized sorting with query complexity , where is the number of vertices and is the number of edges. The algorithm is obtained by combining the convex-geometric approach of [11] with the predictions-based approach of [4].
Interestingly, if we instantiate for some , then the running time becomes , which is precisely what the previous state of the art was was for the stochastic generalized sorting problem (in the sparse case of ) [11].
Other related work.
The original bounds by Huang et al.[11] for both the worst-case and the stochastic generalized sorting problems remained unimproved until now. The difficulty of these problems has led researchers to consider alternative formulations that are more tractable. Banerjee and Richards [4] considered the worst-case generalized sorting problem in the setting where is very dense, containing edges for some parameter , and gave an algorithm that performs comparisons; whether this is optimal remains open, and the best known lower bound is [5]. Banerjee and Richards [4] also gave on alternative algorithm for the stochastic generalized sorting problem, achieving comparisons, but this bound is never better than that of [11] for any . Work by Lu et al. [14] considered a variation on the worst-case generalized sorting problem in which we are also given predicted outcomes for all possible comparisons, and all but of the predictions are guaranteed to be true. The authors [14] show that, in this case, it is possible to sort with only comparisons.
The generalized sorting problem is also closely related to the problem of sorting with comparison costs. In this problem, we are given as input nonnegative costs , where is the set of elements that must be sorted and is the cost of comparing to . The goal is to determine the true order of at a cost that is as close as possible to the optimal cost
If all comparisons have equal costs, the problem reduces to traditional sorting and the optimal competitive ratio is . On the opposite side of the spectrum, if the costs are allowed to be arbitrary, then the best achievable competitive ratio is known to be [9]. Nonetheless, there are many specific families of cost functions for which better bounds are achievable. Gupta and Kumar [9] consider the setting in which each of the elements represents a database entry of some size , and the costs are a function of the sizes and ; two especially natural cases are when or , and in both cases, a competitive ratio of can be achieved [9].111 The authors [9] also describe an algorithm for arbitrary monotone cost functions, but the analysis of the algorithm has been observed by subsequent work to be incorrect in certain cases [12]. Several other families of cost functions have also been considered. Gupta and Kumar [10] consider the setting in which the costs induce a metric space over the elements , and give a -competitive algorithm. In another direction, Angelov et al. [3] consider costs that are drawn independently and uniformly from certain probability distributions (namely, the uniform distribution on , and the Bernoulli distribution with ), and give a -competitive algorithm in each case. The unifying theme across these works is that, by focusing on specific families of cost functions, polylogarithmic competitive ratios can be achieved.
The generalized sorting problem can also be interpreted in this cost-based framework, with queryable edges having cost 1 and un-queryable edges having cost . The presence of very large (infinite) costs significantly changes the nature of the problem, however. The fact that some edges simply cannot be queried makes it easy for an algorithm to get “stuck”, unable to query the edge that it needs to query in order to continue. Whereas sorting with well-behaved (and bounded) cost functions is, at this point, a relatively well understood problem, the problem of sorting with infinite costs on some edges (i.e., generalized sorting) has remained much more open.
1.1 Roadmap
In Section 2, we provide a technical overview of our stochastic generalized sorting algorithm and its analysis. This result is our most interesting and technically involved result. In Section 3, we provide a full description and analysis of the stochastic generalized sorting algorithm, which uses queries on a random graph . In Section 4, we prove that this algorithm is essentially optimal on random graphs. In Section 5, we provide an improved worst-case generalized sorting algorithm that uses queries on an arbitrary graph with vertices and edges.
2 Technical Overview
In this section, we give a technical overview of the main technical result of the paper, which is our algorithm for stochastic generalizing sorting that runs in queries.
The setup.
Suppose that we are given an instance of the stochastic generalized sorting problem, where , and where is the edge sampling probability. Let denote the true order of the vertices (and recall that we use to denote that ). Note that the edges are all included deterministically in , and that each other edge is included independently and randomly with probability . Further note that the edges in are undirected, so the edge is the same as the edge .
The basic algorithm design.
The algorithm starts by constructing sets of edges , where and where each consists of roughly a fraction of all the edges . These sets of edges are constructed once at the beginning of the algorithm, and are never modified.
The algorithm then places the vertices into levels , where is some large positive constant. The top levels automatically contain all of the vertices. To construct the lower levels, we use the following promotion rule to determine whether a given vertex in a level should also be placed into level : if there is some vertex such that and , then we consider to be blocked by ; otherwise, if there is no such , then gets promoted to level .
As we shall describe shortly, our algorithm discovers the true order of the vertices one vertex at a time. At any given moment, we will use to denote the most recently discovered vertex in the true order, and we will say that each remaining vertex , , has rank .
Before we describe how to discover the true order of the vertices, let us first describe how the levels are updated as we go. Intuitively, the goal of this construction is to make it so that, at any given moment, each level has size roughly , and so that the majority of the elements in have rank . We refer to as the target size for level .
Whenever we discover a new vertex (i.e., we discern that some vertex is the -th vertex in the true order), we perform incremental updates to the levels as follows: we remove from all of the levels, and then for each vertex that was previously blocked from promotion by , we apply the promotion rule as many times as necessary to determine what new level should be promoted to. Note that, when we apply the promotion rule to a vertex in a level , we apply it based on the current set , and even if the set changes in the future, we do not consequently “unpromote” the vertex.
In addition to the incremental updates, we also periodically rebuild entire levels from scratch. In particular, we rebuild the levels whenever the number of vertices that we have discovered is a multiple of . (Recall that is our target size for each level .) To rebuild a level , we take the vertices currently in and apply the promotion rule to each of them (based on the current values of the sets and ).
We remark that, whereas incremental updates can only promote vertices (and cannot unpromote them), the process of rebuilding the levels , one after another, can end up moving vertices in both directions. Moreover, there are interesting chains of cause and effect. For example, if a vertex gets unpromoted from level (so now it no longer appears in ), then that may cause some vertex to no longer be blocked, meaning that now gets promoted to ; the addition of to may block some from being able to reside in level , causing to get unpromoted from , etc.
Having described how we maintain the levels , let us describe how we use the levels to discover the next vertex . We first construct a candidate set consisting of the vertices such that . Then, for each , we determine whether by going through the levels in order of , and querying all of the edges between and the level ; we can remove from the candidate set if we ever find an edge , where is in some and . In particular, all vertices have already been discovered and removed from the levels , so the existence of such a vertex implies that .
In the worst case, the process for eliminating a vertex from the candidate set might have to look at all of the edges incident to . One of the remarkable features of our algorithm is that, because of how the levels are structured, the expected number of queries needed to identify ends up being only .
The structure of the analysis.
In the rest of the section, we discuss how to bound the expected number of edge queries made by the algorithm. For now, we will ignore issues surrounding whether events are independent, and we will think of events that are “morally independent” as being fully independent. One of the main challenges in the full analysis is to define the events being analyzed in such a way that these interdependence issues can be overcome.
Our analysis proceeds in three parts. First we analyze for each vertex and each level the probability that at any given moment. Next, we use this to bound the total number of queries spent maintaining the levels . Finally, we bound the number of queries spent eliminating candidates from candidate sets (i.e., actually identifying each ).
Understanding which vertices are in which levels.
Consider a vertex with rank . We will argue that is likely to appear in the levels and is unlikely to appear in the levels .
Begin by considering for some . If , then there must be some vertex with rank such that the edge is in one of . However, there are only total vertices with ranks , and only a -fraction of them have an edge to . Moreover, only a fraction of those edges are expected to appear in one of . So the probability of any such edge appearing is that most
In other words, if has rank , then
(1) |
for each level .
An important consequence of (1) is that, for any given , the vertices with ranks less than (say, less than ) each have probability at least of being in . We refer to the set of such vertices in as the anchor set . At any given moment, we have with reasonably high probability that .
The anchor sets play a critical role in ensuring that vertices with large ranks do not make it into low levels. Consider again a vertex with rank and let us bound the probability that for some . Assume for the moment that . The only way that can be promoted to is if there are no edges in that connect to an element of the anchor set (in particular, if there is such an edge, then will be blocked from promotion). However, the anchor set has size at least , and thus the expected number of edges (in all of ) from to is roughly . A fraction of these edges are expected to be in . Thus, the expected number of edges that block from promotion is roughly
Since these edge-blockages are (mostly) independent, the probability that no such edges block from promotion ends up being at most
This analysis considers just the promotion of from level to level . Applying the same analysis repeatedly, we get that for any vertex with rank , and any ,
(2) |
Or, to put it another way, for each level , and for each vertex satisfying for some , we have that
(3) |
The derivation of (3) reveals an important insight in the algorithm’s design. One of the interesting features of the promotion rule is that, when deciding whether to promote a vertex from a given level into , we use the edges in to compare not to its companions in (as might be tempting to do) but instead to the elements of the larger level . For vertices with small ranks, this distinction has almost no effect on whether makes it into level (note, in particular, that the proof of (1) is unaffected by the choice of !); but for vertices with large ranks (i.e., ranks at least ), this distinction makes the filtration process between levels much more effective (i.e., the larger that is, the stronger that (3) becomes). It is important that not be too large, however, since otherwise the application of (3) to a given would only tell us information about vertices with very large ranks. By setting to be a large positive constant, we get the best of all worlds.
The derivation of (3) also reveals the reason why we must perform periodic rebuilds of levels. We rely on the anchor set to ensure that vertices with large ranks stay out low levels , but the anchor set changes dynamically. Since takes many different values over time, the result is that a given high-rank vertex might at some point get lucky and encounter a state of that allows for to get promoted to level (despite ’s large rank!). The main purpose of performing regular rebuilds is to ensure that this doesn’t happen, and in particular, that the vertices in level were all promoted into based on a relatively recent version of the anchor set .
Bounding the cost of level updates.
The next step of the analysis is to bound the number of queries spent rebuilding levels and performing incremental updates to them.
We can deduce from (3) that, at any given moment, . For our discussion here we will simply assume that always holds.
Now let us consider the number of queries needed to perform a promotion test (i.e., to apply the promotion rule) on a given vertex in a given level . The promotion rule requires us to examine every edge in that goes from to any vertex in . The expected number of such edges is roughly
(4) |
Thus we can treat each promotion test as taking queries.
We can now easily bound the total work spent rebuilding levels from scratch. Each level is rebuilt times, and each rebuild requires us to apply the promotion rule to different vertices. It follows that each rebuild takes queries, and that the total number of queries spent performing rebuilds on is . Summing over the levels results in a total of queries.
What about the query complexity of the incremental updates to the levels? Recall that whenever we discover a new , we must revisit every vertex that was formerly blocked by . For each such , we must check whether can be promoted, and if so then we must repeatedly promote until it reaches a level where it is again blocked.
Recall that each promotion test takes expected queries. To bound the total number of promotion tests due to incremental updates, we break the promotion tests into two categories: the failed promotion tests (i.e., the promotion tests that do not result in a promotion) and the successful promotion tests (i.e., the promotion tests that do result in a promotion).
The number of failed promotion tests is easy to bound. It is straightforward to show that the expected number of distinct vertices that we perform a promotion test on (each time that a new is discovered) is (roughly speaking, there will be one such vertex per level). Each such can contribute at most one failed promotion test. So summing over the ’s, we find that the total number of failed promotion tests is .
To bound the number of successful promotion tests, on the other hand, we can simply bound the number of promotions that occur (due to incremental updates). Each time that some vertex is promoted from a level to a level , the size of increases by one (and the size of is unchanged). We know that the size of each stays below at all times, however, so there can be at most such promotions between every two consecutive rebuilds of the level. Since is rebuilt times, the total number of promotions into is . Summing over the levels, we get , as desired.
Bounding the cost of eliminating candidates from candidate sets.
The final and most interesting step in the analysis is to bound the total number of queries spent eliminating candidates from candidate sets. Suppose we have already discovered vertices , and we wish to discover . How many queries does it take to identify which element of is ?
For simplicity, we will assume here that all of the candidates (besides ) have ranks at least (this assumption can easily be removed with a bit of extra casework).
We can start by bounding the probability that a given is in . In order for to be in we need both that and that is an edge. With a bit of manipulation, one can deduce from (3) that if a vertex has rank , then
If (but ), then . Thus
If , then we must look at all of the edges from to the levels until we find an edge with . Since each level has size , the expected number of edges from to a given is . If is the highest level that we look at while eliminating from , then the total number of queries incurred will be roughly
So how many levels must we look at in order to eliminate from ? Let be the predecessor to in the true order, and let be the lowest level that contains . Since and since is deterministically an edge, we are guaranteed to stop at a level . We can bound (and thus ) by applying (1); this gives us the identity
(5) |
for every .
To summarize, if (and ), then the expected number of queries to remove from is roughly ; and for any , the probability that is . There are possible values for , each of which contributes to . Thus the expected number of queries to remove from is .
To bound the cost of eliminating all candidates from , we must sum over the ranks to get
This represents the cost to identify a given . Summing over all , the total contribution of these costs to the query complexity of the algorithm of is .
3 Stochastic Generalized Sorting
3.1 Algorithm Design
Conventions and Notation.
Let be the input graph and let denote the true order of the vertices.
There are two types of edges in the graph, those that were included randomly with probability , and those that are part of the true path connecting together . We say that a vertex pair is stochastic if it is not an edge in the true-ordering path and otherwise the vertex pair is deterministic. Note that a stochastic vertex pair does not need to have an edge connecting it, but a deterministic vertex pair does.
Our algorithm will find one at a time. Once we have found , we say that has been discovered. As a convention, we will use to denote the most recently discovered vertex. When we refer to the rank of a vertex, we mean its rank out of the not yet identified vertices . For a vertex , we let be the rank of , so .
To simplify our discussion in this section, we will consider only the task of discovering the vertices . This allows for us to assume that the number of remaining vertices is always . Moreover, by a symmetric argument, we can recover and therefore recover the complete order, so this assumption does not affect the correctness of the overall algorithm.
Constructing edge sets .
The first step of our algorithm is to use the following proposition to construct sets of edges (these sets are built once and then never modified). When discussing these sets of edges, we will use to denote the indicator random variable for whether , and we will use to denote the tuple . The proof of Proposition 1 is deferred to Subsection 3.3.
Proposition 1.
Suppose we are given but we are not told which vertex pairs are stochastic/deterministic. Suppose, on the other hand, that Alice is told which vertex pairs are stochastic/deterministic, but is not given . Based on alone, we can construct sets of edges such that , and such that, from Alice’s perspective, the following properties hold:
-
•
For each stochastic vertex pair , , where is some constant that depends only on and .
-
•
For each deterministic vertex pair , .
-
•
The random variables are mutually independent.
-
•
The random variables are mutually independent.
We remark that the sets do not partition , as the sets are not necessarily disjoint. The sets are constructed independently across edges, but for each edge in we anti-correlate the events so that the events are independent if we do not condition on the set . We formally show how to construct the sets in the proof of the above proposition, in Subsection 3.3.
One thing that is subtle about the above proposition is that the randomization is coming from two sources, the random generation of and the random construction of based on . The probabilities in the bullet points depend on both sources of randomness simultaneously, and they do not condition on the final edge set (hence, the use of Alice in the proposition statement).
Assigning the vertices to levels.
A central part of the algorithm design is to use the edge sets in order to dynamically assign the vertices to levels , where is as defined above and is some large but fixed constant. Before we can describe how the algorithm discovers the true order of the vertices, we must first describe how the levels are constructed and maintained over time. In particular, the algorithm will make use of the structure of the levels in order to efficiently discover new vertices in the true order.
Intuitively, the goal of how the levels are maintained is to make it so that, at any given moment, each level has size roughly , and so that the majority of the elements in have ranks . We refer to as the target size for level .
Initial construction of levels.
We perform the initial construction of the levels as follows. The final levels all automatically contain all of the vertices. For each other level , we construct the level as
(6) |
The vertices from that are not included in are said to be blocked by the edge defined in (6).
One point worth highlighting is that, when we are deciding whether a vertex should move from to , we query not just the edges in that connect to other vertices in , but also the edges that connect to other vertices in the larger set . This may at first seem like a minor distinction, but as we shall later see, it is critical to ensuring that vertices with large ranks do not make to levels for small .
Performing incremental updates to levels.
When we discover a given , we perform incremental updates to the levels as follows. First, we remove from all of the levels. Next we consider vertices that were formerly blocked by an edge of the form in some level : since is no longer in the levels, no longer blocks . Since has been removed from the levels, we must give the opportunity to advance to lower levels. That is, if there is no edge such that , then we advance to level ; if, additionally, there is no edge , then we advance to level , and so on. The vertex continues to advance until it is either in the bottom level or it is again blocked by an edge.
Rebuilding levels periodically.
In addition to the incremental updates, we also periodically reconstruct each level in its entirety. Recall that we use to denote the target size for each level . For each , every time that the index of the most recently discovered is a multiple of , we rebuild the levels , one after another, from scratch according to (6). That is, we rebuild level based on the current values of and , we then rebuild based on the new value of and the current value of , etc.
Note that, when rebuilding a level from scratch, we also redetermine from scratch which of the vertices in are blocked from entering . In particular, a vertex may have previously been blocked from entering by an edge for some ; but if has since been rebuilt, then might no longer be in , and so may no longer be blocked from entering level .
Finding the first vertex.
We are now ready to describe how the algorithm discovers the true order of the vertices. We discover the first vertex in a different way from how we discover the other vertices (and, in particular, we do not make use of either the edge sets or the levels ).
The algorithm for finding works as follows. We always keep track of a single vertex which will be the earliest vertex found so far (in the true ordering) and a set of vertices that we know come after in the true ordering. We begin by picking an arbitrary edge and querying the edge to find which vertex precedes the other. If precedes , we set and ; else, we set and . For each subsequent step, if we currently have and then we do the following. If there exists any edge connecting and some we query the edge If precedes , then we add to the set . Otherwise, if precedes , we add to the set , and then replace with . Finally, if there is no edge connecting with some we obtain that .
Finding subsequent vertices.
Now suppose we have most recently discovered some vertex and we wish to discover . This is done using the levels and the edge sets as follows.
We start by constructing a candidate set consisting of all of the vertices in that have an edge to . Next, we perform the following potentially laborious process to remove vertices from the candidate set until we have gotten down to just one candidate. We go through the levels , and for each level we query all of the edges between vertices in and the remaining vertices in . We remove a vertex from the candidate set if we discover an edge with . Once we have narrowed down the candidate set to a single vertex, we conclude that the vertex is .
By repeating this process over and over, we can discover all of the vertices .
3.2 Algorithm Correctness
In this subsection, we prove StochasticSort always outputs the correct order (with probability ). First, we show that the algorithm finds correctly.
Proposition 2.
The algorithm for finding always succeeds. Moreover, it deterministically uses at most queries.
Proof.
First, we note that at any step, if we have vertex and set , then for all . This is obviously true at the first step after we compare the first two vertices , and it continues to be true later on by the following inductive argument. If we find some edge with , then if , then for all , so adding to and replacing with means the new still precedes all vertices in . On the other hand, if then since we just add to , we also still have that precedes everything in . Thus we always have for all .
Next we show that, whenever our algorithm for finding terminates, it is guaranteed to have successfully found . That is, we show that if has no edges such that , then must equal . This is because if then is connected to its immediate predecessor in the true ordering (which we can call ), which would mean . This, however, contradicts the fact that for all . Therefore, our algorithm is correct assuming it terminates.
Finally, observe that the algorithm must terminate after queries, since each query increases the size of by (we either add or to , neither of which was in before). This concludes the proof. ∎
Next, we give a condition that guarantees that a given vertex will be in a given level .
Proposition 3.
Fix a vertex that has not been discovered yet, and suppose that at some point, for all such that has not been discovered, . Then, is in level .
Proof.
Suppose that . Then, since is not in the first level, the algorithm currently states that is blocked by some edge with .
Since the algorithm currently states that is blocked by , the vertex cannot have been discovered yet. Indeed, once is discovered, we remove from all levels and perform incremental updates to all of the vertices that edges incident to blocked, including . This incremental update would either push all the way to level or would result in being blocked by a new edge (different form the edge )), contradicting the fact that is currently blocked by . So, and is not discovered. Finally, since , there exists some such that , which means that since the algorithm decided that blocks from level , we have that . ∎
As a direct corollary, we have the following:
Corollary 4.
After are discovered and all level updates are performed, .
Proof.
Indeed, there are no vertices such that has not been discovered. So, by setting and in Proposition 3, the corollary is proven. ∎
To finish the proof of algorithm correctness, suppose we have discovered and we are now in the process of discovering . Since (by Corollary 4), the set of vertices in that are connected to contains . For each such that , the immediate predecessor of is undiscovered, so it is in . Moreover, the immediate predecessor of has an edge connecting it to . Therefore, the other vertices will be eliminated eventually. However, can never be eliminated, since are the only vertices that precede , and they have been removed from all levels. Therefore, eventually we will narrow down the candidate set to precisely , meaning that we will successfully discover the correct value for . The proof of correctness follows by induction.
3.3 Analyzing the Query Complexity
In this section we bound the total number of queries made by the StochasticSort algorithm. First, as promised in Subsection 3.1, we prove Proposition 1.
Proof of Proposition 1.
Recall that (i.e., the number of edge sets ) is defined solely as a function of and . Choose so that
(7) |
Note that is a continuous and strictly decreasing function over . Moreover, and Thus, there is a unique solution to , and the solution must be in the range .
Let be the probability distribution over tuples of the form , where each is an indicator random variable that is independently set to with probability . To construct the s, for each edge we sample at random from the distribution conditioned on at least one of the s being ; and for each edge , we set to be the zero tuple. Note that, by design, .
Now let us analyze the sets from Alice’s perspective (i.e., conditioning on which edges are stochastic/deterministic but not on which edges are in ). For each stochastic vertex pair , the pair is included in with probability . This is exactly the probability that a tuple sampled from is non-zero. Thus, for each stochastic vertex pair , we independently have . (This implies the first property.) On the other hand, for each deterministic vertex pair , we independently have . Observe that for ,
where the first equality uses the fact that can only hold if holds, and the second equality uses (7). This establishes that for any deterministic vertex pair , , hence the second property. Finally, the aforementioned independencies imply the third and fourth properties, with the third property (independence if we do not condition on ) also using the fact that we chose to satisfy Equation (7). ∎
Throughout the rest of the algorithm analysis, whenever we discuss the events , we will be taking the perspective of Alice from Proposition 1. That is, our analysis will be considering both the randomness that is involved in selecting stochastic edges, and the randomness that our algorithm introduces when constructing the s.
For now, we shall assume that is at least a sufficiently large constant multiple of ; this assumption means that the target size for each level satisfies for all , and will allow for us to use high probability Chernoff bounds in several places. We will remove the assumption at the end of the section and extend the analysis to consider arbitrary values of .
Assume that the first vertices have been discovered, and we are in the process of identifying . Recall that, for each vertex pair , and for each level , we use to denote the indicator random variable for the event that . Let be the indicator random variable
for the event that any vertex pair with is contained in any of . Note that there is no restriction on as to which levels contain it (all are considered). For a given vertex satisfying , if then is guaranteed to be in , but the reverse does not hold ( could be in despite being ).
The random variables are independent across vertices (but not across levels), since even for deterministic edge pairs we still have independence of across vertex pairs (see the fourth property of Proposition 1). Moreover, each satisfies the following useful inequality:
Lemma 5.
Suppose has rank . Then
where is the positive constant defined in the construction of the s.
Proof.
By the union bound,
Recall from Proposition 1 that each stochastic vertex pair has probability at most of being included in , and that each deterministic vertex pair has probability at most of being included in . Thus
Whenever a level is rebuilt, we define the anchor vertices to be the vertices in with ranks in the range
Note that, even as changes incrementally over time, the anchor set does not change until the next time that is rebuilt from scratch. Moreover, because is rebuilt relatively frequently (once for every vertices that are discovered), no anchor vertices are ever removed from (until after the level is next rebuilt). Moreover, the rank of any anchor vertex is always between and , since the rank is initially at least and decreases by a total of between rebuilds.
Our next lemma establishes that, with high probability, there are a reasonably large number of anchor vertices in each level at any given moment. Recall that is used to denote the rank of a given vertex .
Lemma 6.
Let . Then, with probability at least ,
Proof.
For any vertex , if , then must be in , as there is nothing that can block it from levels or above. Therefore,
So far, dependencies between random variables have not posed much of an issue. In the subsequent lemmas, however, we will need to be careful about the interaction between which vertices are in each level, which vertices are in each anchor set, and which random variables hold. For this, we will need the following two propositions.
Proposition 7.
At any time in the algorithm, for each vertex and level , the event that only depends on over triples where and (including if or is already discovered).
Proof.
We prove this by induction on . For the proposition is trivial since every vertex (that is not yet discovered) is in level . Assume the claim is true for levels .
Define the sets . By the inductive hypothesis, the sets depend only on over triples where and . If we fix the outcomes of those s, thereby fixing the outcomes of , then whether or not depends only on where and . Thus whether or not depends only on the allowed variables. ∎
Proposition 8.
Conditioned on the sets over all , the random variables are jointly independent over all triples with and with satisfying . Moreover, for each such triple , the probability remains , even after conditioning on the sets .
Proof.
Note that only depends on which of ranks between and are in level . Therefore, by Proposition 7, over all is strictly a function of over all choices with and (possibly including already discovered vertices ). Simplifying, we get that over all is strictly a function of over all choices of satisfying . Let denote the set of such triples .
We wish to prove the independence of over the set of triples with and . Note that if a triple is in , then we must have that , so . Moreover, so is a stochastic vertex pair. Thus, the triples do not include any deterministic vertex pairs , and are disjoint from the triples on which the anchor sets depend. The conclusion follows from the first and third properties of from Proposition 1. ∎
Now, for each vertex satisfying and for each level such that , define the indicator random variable
In order for to be in any of the levels , we must have that .
The next lemma bounds the probability that for a given vertex .
Lemma 9.
Consider a vertex satisfying , and suppose that we condition on the s such that each has size at least . Then, for each level we have
Moreover, conditioned on the s, the s are mutually independent.
Proof.
Using these observations, we can now bound to the size of each .
Lemma 10.
Each has size at most with probability at least .
Proof.
Recall from Lemma 6 that, with probability at least , we have for every . Condition on some fixed choice of the s, such that for each . Fix , and for each vertex with , let
We claim that, if , then must occur. If does not occur, then there is some such that and some such that But then, at the last time level (and thus all lower levels) was rebuilt, would block from coming to level (and thus from coming to level ), and since has not been removed yet, must not be in .
For a given with , since depends on different s, we have by Lemma 9 that
assuming the constant is sufficiently large. The expected number of satisfying for which holds is therefore at most
By a Chernoff bound (which can be used since the ’s are independent by Lemma 9), the total number of vertices for which and holds is with failure probability at most . This, in turn, means that
On the other hand, can contain at most vertices with . Thus, . ∎
Having established the basic properties of the levels, we now bound the total number of comparisons of the various components of the algorithm.
Lemma 11.
The total expected number of comparisons spent rebuilding levels (from scratch) is .
Proof.
It suffices to show that, for each level , the expected number of comparisons spent performing rebuilds on is . We deterministically perform rebuilds on . Each time that we perform a rebuild, we must query all of the edges in that go from to . By Lemma 10, we know that and are with high probability in . Moreover, by Proposition 7, the levels and only depend on , so by Proposition 1 they are independent of the random variables ranging over the stochastic vertex pairs . Therefore, if we assume that and are , then the expected number of edges that we must query for the rebuild is
since there are at most deterministic vertex pairs and stochastic vertex pairs that we might have to query, and each of the stochastic pairs is included in with probability .
In summary, there are rebuilds of level , each of which requires comparisons in expectation. The total number of comparisons from performing rebuilds on is therefore in expectation. ∎
Recall that, each time that we discover a new vertex in the true order, we must revisit each vertex and each such that and . Because the vertex has been discovered, it is now removed from all of the levels, and thus the edge no longer blocks from advancing to level . If there is another edge such that and , then the vertex remains blocked from advancing to level . If, however, is no longer blocked from advancing, and will advance some number of levels. In this case, we say that performs incremental advancements.
Lemma 12.
The total expected number of queries performed for incremental advancements is .
Proof.
For each level , we only attempt to increment vertices if is blocked by , meaning that . Except for when the event that which occurs with probability , is independent of whether , which only depends on by Proposition 7. By Lemma 10, with probability . It follows that the expected number of vertices that we even attempt to increment, in expectation, is . Over all levels, we increment an expected vertices during each edge discovery (i.e., when trying to find ).
Whenever we try to incrementally advance a vertex that is currently at some level the number of queries that we must perform in order to determine whether should further advance to level is equal to the number of vertices in such that . However, the only information about that we are conditioning on is that is in and that was blocked by . So, by Propositions 1 and 7, the events ranging over for which is a stochastic edge are independent of the information about that we have conditioned on; note that the only for which is not stochastic are the vertices that come immediately before or immediately after in the true order (which we call , ). Therefore, the expected number of queries we must perform is at most , since each vertex in has probability of having an edge in to . By Lemma 10, we know that with probability at least . Thus, the expected number of queries that we must perform for each incremental advancement is .
To prove the lemma, it suffices to show that the expected total number of attempted incremental advancements is , since each one uses an expected queries. Recall that, each time that we try to discover a new vertex we attempt to increment vertices in expectation: each vertex can fail to be incremented only once, because we stop incrementing after that. So, the expected number of failed incremental advancements across the entire algorithm is . In addition, whenever we perform a successful incremental advancement, we increase the size of some level by . We know that, with high probability in , each level never has size exceeding . Between rebuilds of , total vertices are removed from . In order so that , the total number of vertices that are added to between rebuilds must be at most . Thus, between rebuilds, at most vertices are incrementally advanced into . Since is rebuilt times, the total number of incremental advancements into over all time is . Summing over the levels , the total number of incremental advancements is . ∎
After doing the incremental advancements for a given , and performing any necessary rebuilds of levels, the algorithm searches for the next vertex . Our final task is to bound the expected number of queries needed to identify .
Lemma 13.
The expected number of comparisons needed to identify a given (i.e., to eliminate incorrect candidates from the candidate set) is .
Proof.
Consider the candidate set for . In addition, consider a vertex . For to be in the candidate set , the following two events must occur:
-
•
Event 1: must have an edge to .
-
•
Event 2: For all such that , we have .
Event occurs with probability , and only depends on over all . On the other hand, by Proposition 7, the sets only depend on over triples with . Let
be the set of triples whose corresponding variables cumulatively determine Event 1 and the anchor sets .
Event 2 considers for such that (note that these are the only for which is defined), so assuming the s are fixed, it only depends on for triples in the set
Note that is disjoint from , since means and since the fact that means that , so . Moreover, consists exclusively of stochastic vertex pairs, since for any , we have . Thus, if we fix the outcomes of Event 1 and of the anchor sets , then Proposition 1 tells us that the outcomes of the s corresponding to are independent of the random variables that have already been fixed.
Now let us consider the probability of Event 2 if we condition on Event 1 and if we condition on the sets each having size at least . There are random variables for which , and by Lemma 9 each independently has probability at most of being (based on the outcomes of the random variables where is selected so that ). So conditioned on the outcome of Event 1 and on the sets each having size at least , Event 2 occurs with probability at most
Let and be the indicator random variables for Events 1 and 2, respectively, and let be the indicator that for all . To summarize, we have so far shown that and that
Let be the true predecessor of . As soon as we query the edge , we will be able to eliminate from the candidate set. Thus, if is in the candidate set, then we can upper bound the number of queries needed to eliminate by the number of query-able edges from to each level for which .
Now consider a fixed level . In order so that , we must have that:
-
•
Event 3: .
Event 3 depends only on where and . This means that the events that determine Event 3 concern different pairs of vertices than do the events that determine Event 1 (since the latter events all involve ’s successor ); and the events that determine Event 3 concern different pairs of vertices than do the events that determine Event 2 once the s are fixed (since, once again, the latter events all involve ’s successor ). Importantly, by the fourth property of Proposition 1, this means that Event and Event are independent if we do not condition on the s, and that conditioning on Events and along with the s does not affect the probability of Event in comparison to conditioning only on Event 1 and the s (and not on Event 3).
Let be the indicator for Event 3. By Lemma 5,
Thus we have that
We remark that, although Events 1, 2, 3 are formally defined only for (since there is no level ), if we also consider a level to be the empty set (so by default), we have that , so our bound for is still true even in the case of .
For any vertex , if ’s predecessor is in for some (where ), then once we have queried edges from to we will have found , eliminating from the candidate set. Hence, for any level , we will only query edges from to if Event 3 occurs for level , and we only query edges from to if Event occurs for some in the original candidate set (since otherwise we will have eliminated all vertices except ).
We have already bounded the probability of any of Events 1, 2, 3 occurring for a given and level . Therefore, if we wish to bound the number of edges that are queried while discovering , then our final task is the following: for each and level (including ), we must bound the number of query-able edges from to , conditioning on Events 1, 2, 3 occurring for and . We do not need to count any edge that has already been queried in the past. There are at most deterministic edges incident to . On the other hand, if we condition on which edges have been queried in the past, and we also condition on Events 1, 2, and 3, then each remaining stochastic vertex pair (that is not yet been queried) has conditional probability at most of being a query-able edge. In particular, for each stochastic vertex pair that has not been queried, the only information that our conditions can reveal about it is that there is some set of s in which the vertex pair is known not to appear222Note, in particular, that every time that the algorithm checks whether some edge is in or is in some , if the algorithm finds that the edge is, then it immediately queries the edge (unless , in which case we already know the direction of the edge since , so we will never need to query it). Thus, the only information that the algorithm ever learns about not-yet-queried/not-yet-solved edges is that those edges are not in some subset of the s. (This can also easily be verified by the pseudocode in Appendix A.); and this can only decrease the probability that the vertex pair is a query-able edge. Since with high probability in , the expected number of edges that we must query from to (and if we condition on Events 1, 2, 3) is (unless the combined probability of Events 1, 2, 3 is already , in which case we can use the trivial bound of on the number of edges that we query).333Note that , and thus the bound of also counts the deterministic edges that we might have to query.
Combining the pieces of the analysis, and setting , the expected number of comparisons that we incur removing vertices from ’s candidate set is at most
Furthermore, we can write the sum
substituting . Therefore, in total, the expected number of comparisons that we incur while removing vertices from ’s candidate set is ∎
The preceding lemmas, along with subsection 3.2, combine to give us the following theorem:
Theorem 14.
The expected number of comparisons made by the StochasticSort algorithm is . Moreover, the algorithm always returns the correct ordering.
We conclude the section by revisiting the requirement that is at least a sufficiently large constant multiple of . Recall that this requirement was so that all of the level sizes would be large enough that we could apply Chernoff bounds to them. We now remove this requirement, thereby completing the proof that Theorem 14 holds for all . Consider an index for which is a large constant multiple of . We can analyze all of the levels , , as before, but we must analyze the levels below level differently. One way to upper bound the number of edge queries in the levels below is to simply assume that every pair of vertices in is queried as an edge. Even in this worst case, this would only add queries between every pair of consecutive rebuilds of (since the number of distinct vertices that reside in at any point between a given pair of rebuilds is ). There are total rebuilds of , and thus the total number of distinct queries that occur at lower levels over the entire course of the algorithm is upper bound by . Thus Theorem 14 holds even when .
4 Lower Bound for Stochastic Generalized Sorting
In this section, we prove that our stochastic generalized sorting bound of is tight for . In other words, for even slightly greater than , generalized sorting requires at least queries (to succeed with probability at least ) on an Erdős-Renyi random graph (with a planted Hamiltonian path to ensure sorting is possible). Formally, we prove the following theorem:
Theorem 15.
Let and be known. Suppose that we are given a random graph created by starting with the Erdős-Renyi random graph , deciding the true order of the vertices uniformly at random, and then adding the corresponding Hamiltonian path. Then, any algorithm that determines the true order of with probability at least over the randomness of the algorithm and the randomness of must use queries.
The main technical tool we use is the following bound on the number of Hamiltonian cycles in a random graph, due to Glebov and Krivelevich [8]:
Theorem 16.
For , the number of (undirected) Hamiltonian cycles in the random graph is at least , with probability as goes to .
A consequence of this is that, for the graph in Theorem 15, the total number of undirected Hamiltonian paths is, with probability , also at least .
We will think of the graph in Theorem 15 as being constructed through the following process. First, Alice chooses a random permutation of the vertices and makes the true ordering . Then, she adds the edges . Finally, for each pair of vertices that are not consecutive in the true order, she adds to with probability . We use to denote the undirected graph that Alice has constructed, and we use to denote the directed graph.
Now, suppose an adversary sees the undirected graph with the planted Hamiltonian path. In addition, suppose the adversary knows some set of directed edges (where, as undirected edges, ). Now, consider a permutation such that are all undirected edges in , and such that the known orders in do not violate . We say that such permutations are consistent with and .
The next proposition tells us that the adversary cannot distinguish the true order from any other permutation that is consistent with and . In other words, the adversary must treat all possible Hamiltonian paths as equally viable.
Proposition 17.
Suppose we know as well as a subset of directed edges. Then, the posterior probability of the true ordering of the vertices is uniform over all that are consistent with and .
Proof.
For each permutation , define to be the event that Alice chose the permutation . Define to be the event that the undirected graph constructed by Alice is the graph , and define be the event that every directed edge is in the directed graph . Then, the initial probability that Alice created (before we are told or any of the orders of ) is precisely
(8) |
This is because she decided with probability each stochastic edge in (of which there are of them) is included with probability , and each non-edge vertex pair is excluded with probability . Finally, given we know that the event is also true. As a result, even if we condition on and , this means
which by (8) is the same for every that is consistent with the fixed . Hence, knowing and means each permutation that is consistent with and is equally likely. ∎
At this point, the remainder of the proof of the lower bound is relatively simple. The idea is that initially, using Theorem 16, there are possible choices for . But each query cannot give more than bit of information about , so one would need queries to determine We now prove this formally.
Proof of Theorem 15.
Suppose that is a graph with Hamiltonian paths for some fixed constant , which is true with probability at least . By Proposition 17, unless we have narrowed down the possible permutations to , we have at most a probability of guessing the true permutation. Therefore, to guess the true permutation with probability overall using queries, we must be able to perform queries to reduce the number of consistent permutations to , with probability at least .
Now, after performing queries, suppose there are potential consistent permutations. At the beginning, , which means . Now, suppose we have possible permutations at some point and we query some edge . Then, for some integers such that either we will reduce the number of permutations to or reduce the number of permutations to , depending on the direction of . Due to the uniform distribution of the consistent edges (by Proposition 17), the first event occurs with probability and the second event occurs with probability . Therefore, the expected value of , assuming we query this edge , is
where is known to be at most for . (Note that we are using the convention that ).
Therefore, no matter what edge we query, the expected value of is at least Hence, for any , regardless of the choice of queries that we make. So, after queries, the random variable is bounded in the range and has expectation at least . Therefore, is at most by Markov’s inequality on the random variable . Since is equivalent to there being exactly one choice for the true permutation , we have that queries is not sufficient to determine uniquely with success probability at least . This concludes the proof. ∎
5 Generalized Sorting in Arbitrary (Moderately Sparse) Graphs
In this section, we improve the worst-case generalized sorting bound of [11] from to . Hence, for moderately sparse graphs, i.e., , we provide a significant improvement over [11].
The main ingredients we use come from the papers [11], which provides a convex geometric approach that is especially useful when we are relatively clueless about the true order, and [14], which shows how to efficiently determine the true order given a sufficiently good approximation to ordering.
Suppose that the original (undirected) graph is some and that at some point, we have queried some subset of (directed) edges and know their orders. We say that a permutation is compatible with and if for every directed edge , according to . (Note that being compatible is a slightly weaker property than being consistent, as defined in Section 4, because compatibility does not require that appear as a Hamiltonian path in .) Let be the set of permutations that are compatible with and . Moreover, for any vertex , define to be the (unweighted) average of the ranks of among all . Huang et al. [11] proved the following theorem using an elegant geometric argument:
Theorem 18 (Lemma 2.1 of [11]).
Suppose that Then, where represents the directed edge
The above theorem can be thought of as follows. If we see that in the true ordering but previously the expectation of ’s rank under all compatible permutations was larger than the expectation of ’s rank under all compatible permutations, then the number of compatible permutations decreases by a constant factor.
In addition, we have the following theorem from [14]:
Theorem 19 (Theorem 1.1 of [14]).
Let be the true directed graph of (with respect to the true permutation ) and let be some given directed graph of , such that at most of the edge directions differ from . Then, given the graph , (but not ), and , there exists a randomized algorithm PredictionSort() using queries that can determine with high probability.
Our algorithm, which we call SparseGeneralizedSort, works as follows. Set a parameter to be for some sufficiently large positive constant . We repeatedly apply the following procedure until we have found the true ordering.
-
1.
Let be the current set of queried edges and be the set of compatible permutations. If then there is only one option for the permutation, which we return.
-
2.
Else, choose as the permutation of ordered where occurs before if We break ties arbitrarily.
-
3.
Let be our “approximation” for the true directed graph , where if comes before in the order.
-
4.
Query random edges from .
-
5.
If all edges match the same direction as our approximation , we use the algorithm of Theorem 19 with the parameter set to . If not, we add the mispredicted edges and their true directions to , and we return to the first step.
Theorem 20.
SparseGeneralizedSort makes at most queries and successfully identifies the true order of the vertices with high probability.
Proof.
To analyze the algorithm, we must bound the number of queries that it performs, and we must also bound the probability that it fails. Note that there are two ways the algorithm can terminate, either by achieving in Step , or by invoking the algorithm of Theorem 19 in Step . (In the latter case, our algorithm terminates regardless of whether the algorithm from Theorem 19 successfully finds the true order or not.)
First, we bound the number of queries. Note that the only queries we make are at most the random queries in each loop plus the queries made by a single application of Theorem 19. Hence, if we repeat this procedure at most times, we make at most total queries.
Now, each time we repeat this procedure, this means that we found an edge that went in the opposite direction of our approximation , meaning that we found an edge such that Then, by Theorem 18, Thus, each iteration of the procedure decreases the number of compatible edges by at least a factor of Since we start off with compatible permutations, after iterations, we have at most remaining permutations. So after iterations, we are guaranteed to be down to at most permutation, ensuring that Step 1 terminates the procedure. Therefore, we make at most total queries.
Finally, we show that that the algorithm succeeds with high probability. Note that there are two ways that the algorithm could fail: the first is that Step invokes the algorithm from Theorem 19 even though there are more than mispredicted edges in ; and the second is that Step correctly invokes the algorithm from Theorem 19, but that algorithm fails. By Theorem 19, the latter case happens with low probability, and thus our task is to bound the probability of the first case happening.
Suppose that for some given , the number of incorrect edges is more than . Then, the probability of a random edge being incorrect is at least . So, if we sample edges, at least one of the edges will be wrong with probability
Therefore, at each time we query random edges from , with failure probability , we either find an incorrect direction edge in or the number of incorrect direction edges in is at most . Since we only repeat this loop at most times, the probability that we ever incorrectly invoke the algorithm of Theorem 19 is at most . ∎
Remark.
Unlike the stochastic sorting algorithm, it is not immediately clear how to perform SparseGeneralizedSort in polynomial time, since the average rank is difficult to compute. We briefly note, however, that can be approximated with error in polynomial time by sampling from the polytope in with facets created by if we know that , for each pair (see Lemma 3.1 of [11] as well as discussion in [7] for more details). Moreover, these approximations suffice for our purposes, since it is known (see Lemma 2.1 of [11]) that Theorem 18 still holds even if (although the modified theorem now has a different constant than ).
Acknowledgments
S. Narayanan is funded by an NSF GRFP Fellowship and a Simons Investigator Award. W. Kuszmaul is funded by a Fannie & John Hertz Foundation Fellowship; by an NSF GRFP Fellowship; and by the United States Air Force Research Laboratory and the United States Air Force Artificial Intelligence Accelerator and was accomplished under Cooperative Agreement Number FA8750-19-2-1000. The views and conclusions contained in this document are those of the authors and should not be interpreted as representing the official policies, either expressed or implied, of the United States Air Force or the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints for Government purposes notwithstanding any copyright notation herein
The authors would like to thank Nicole Wein for several helpful conversations during the start of this project.
References
- [1] N. Alon, M. Blum, A. Fiat, S. Kannan, M. Naor, and R. Ostrovsky. Matching nuts and bolts. In 5th Annual Symposium on Discrete Algorithms, SODA, pages 690–696. ACM/SIAM, 1994.
- [2] N. Alon, P. G. Bradford, and R. Fleischer. Matching nuts and bolts faster. Inf. Process. Lett., 59(3):123–127, 1996.
- [3] S. Angelov, K. Kunal, and A. McGregor. Sorting and selection with random costs. In Theoretical Informatics, 8th Latin American Symposium, LATIN, volume 4957 of Lecture Notes in Computer Science, pages 48–59. Springer, 2008.
- [4] I. Banerjee and D. S. Richards. Sorting under forbidden comparisons. In 15th Scandinavian Symposium and Workshops on Algorithm Theory, SWAT, volume 53 of LIPIcs, pages 22:1–22:13. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2016.
- [5] A. Biswas, V. Jayapaul, and V. Raman. Improved bounds for poset sorting in the forbidden-comparison regime. In Algorithms and Discrete Applied Mathematics - Third International Conference, CALDAM, volume 10156 of Lecture Notes in Computer Science, pages 50–59. Springer, 2017.
- [6] P. G. Bradford. Matching nuts and bolts optimally. Technical Report MPI-I-95-1-025, 1995.
- [7] M. E. Dyer, A. M. Frieze, and R. Kannan. A random polynomial time algorithm for approximating the volume of convex bodies. J. ACM, 38(1):1–17, 1991.
- [8] R. Glebov and M. Krivelevich. On the number of hamilton cycles in sparse random graphs. SIAM J. Discret. Math., 27(1):27–42, 2013.
- [9] A. Gupta and A. Kumar. Sorting and selection with structured costs. In 42nd Annual Symposium on Foundations of Computer Science, FOCS, pages 416–425. IEEE Computer Society, 2001.
- [10] A. Gupta and A. Kumar. Where’s the winner? max-finding and sorting with metric costs. In 8th International Workshop on Approximation Algorithms for Combinatorial Optimization Problems, APPROX, volume 3624 of Lecture Notes in Computer Science, pages 74–85. Springer, 2005.
- [11] Z. Huang, S. Kannan, and S. Khanna. Algorithms for the generalized sorting problem. In 52nd Annual Symposium on Foundations of Computer Science, FOCS, pages 738–747. IEEE Computer Society, 2011.
- [12] S. Kannan and S. Khanna. Selection with monotone comparison costs. In 14th Annual Symposium on Discrete Algorithms, SODA, volume 12, pages 10–17. ACM-SIAM, 2003.
- [13] J. Komlós, Y. Ma, and E. Szemerédi. Matching nuts and bolts in () time. SIAM J. Discret. Math., 11(3):347–372, 1998.
- [14] P. Lu, X. Ren, E. Sun, and Y. Zhang. Generalized sorting with predictions. In 4th Symposium on Simplicity in Algorithms, SOSA, pages 111–117. SIAM, 2021.
Appendix A Pseudocode
In this Appendix, we provide pseudocode for both of our algorithms. Algorithms 1, 2, 3, 4, and 5 comprise the StochasticSort(a)lgorithm, with Algorithm 5 our main routine. Algorithm 6 implements the SparsGeneralizedSort(a)lgorithm.
As a notation, we will use to be the comparison function that takes two vertices connected by an edge, and returns if and if .