Sorting Under 1- ∞ Cost Model
aa r X i v : . [ c s . D S ] N ov Sorting Under 1- ∞ Cost Model
Indranil Banerjee, Dana Richards
George Mason UniversityDepartment Of Computer ScienceFairfax Virginia 22030, USA {ibanerje,richards}@cs.gmu.edu
Abstract.
In this paper we study the problem of sorting under non-uniform comparisoncosts, where costs are either 1 or ∞ . If comparing a pair has an associated cost of ∞ then we say that such a pair cannot be compared (forbidden pairs). Along with the setof elements V the input to our problem is a graph G ( V, E ), whose edges represents thepairs that we can compare incurring an unit of cost. Given a graph with n vertices and q forbidden edges we propose the first non-trivial deterministic algorithm which makes O (( q + n ) log n ) comparisons with a total complexity of O ( n + q ω/ ), where ω is theexponent in the complexity of matrix multiplication. We also propose a simple randomizedalgorithm for the problem which makes e O ( n / √ q + n + n √ q ) probes with high probability.When the input graph is random we show that e O (min ( n / , pn )) probes suffice, where p is the edge probability. Keywords:
Sorting, Random Graphs, Complexity
Comparison based sorting algorithms is one of the most studied area in theoretical computerscience. However, the majority of the efforts have been focused on the uniform comparison costmodel. Arbitrary non-uniform cost models can make trivial problems non-trivial, like findingthe minimum [4, 8]. Thus it makes sense to consider a more structured cost. For example, acommon cost model is the monotone cost model. As shown in [8] the best one can do is to getan algorithm that is within a logarithmic factor of a cost optimal algorithm. However, the 1- ∞ cost model in this paper is not monotonic. This model has comparison cost of 1 or ∞ . A pairwith cost ∞ is considered a “forbidden pair”. The set of pairs with comparison cost 1, defines anundirected graph, G ( V, E ), where V is the set of keys and E represents the allowed comparisons.We call G the comparison graph. Define E f to be the set of forbidden pairs. Let | V | = n and | E f | = q .An example of a problem that uses this model is the nuts and bolts problem. This is strictlynot a sorting problem rather a matching one. In this problem one is given two sets of elements,a set of nuts and a set bolts. Elements in each set have distinct sizes and for each nut it isguaranteed that there exists a unique bolt of same size. Matching is performed by comparinga nut with a bolt. However, pairs of nuts or pairs of bolts cannot be compared. So in this case G = K ( N, B ) is a complete bipartite graph with edges from the set of nuts N to the set ofbolts B . This problem has been solved in the mid 1990s [7,9]. The existence of a O ( n log n ) timedeterministic algorithm was proved for it using the theory on bipartite expanders [7].The problem of sorting with forbidden pairs is still open for the most part. It is closely relatedto the problem of partial sorting under a relation determining oracle. In this model we are givena set P of elements and a oracle O r which is used to determine the relations between pairs ofelements in P . The goal is to determine all the valid relations. Number of queries made to O r isdefined as the query complexity . Since there are Ω (2 n / ) [16] labelled posets with n elements,it immediately follows that the information theoretic bound (ITB) for the query complexityis Ω ( n ). This is has been investigated for width bounded posets in [17], where the authors By monotone we mean that the cost of comparing a pair is a monotone function of the values of thepair. I Banerjee, D Richards show that if P has width at most w then the ITB for the query complexity is O (( w + log n ) n ).They presented a query optimal algorithm for width bounded posets whose total complexity is O ( nw log nw ). Their main contributions were on developing an efficient data structure which wasuse to store a poset as disjoint chains and queries unknown relations using a weighted binarysearch method. This algorithm can be generalized for any poset with an additional log w factoradded to the the query complexity. Their results were the first major extension in this line ofresearch after the seminal work by Faigle and Tur´an [18] which showed existence of such analgorithm. Although an efficient implementation of it were not known at the time. Anothersimilar problem is the local sorting problem. In this problem V is an ordered set and for each( u, v ) ∈ E we want to determine their relative order. The problem is to determine if this can bedone without resorting to sorting the entire set V , since the ITB for this problem is Ω ( n log ∆ )in the standard comparison tree model (where ∆ is the maximum degree of G ). Currently nonon-trivial deterministic algorithm is known for this problem. However, there is a randomizedalgorithm which makes optimal number of comparison with high probability [20].The query model used in this paper differs from [17] in following manner: we don’t charge forchecking whether an edge exists but we only charge for the comparisons made. The number ofcomparisons made or rather asked to the oracle is naturally defined as the comparison complexity or the probe complexity . However, no non-trivial ITB for the probe complexity is known in thestandard decision tree model. We believe that the model is too weak for this purpose. Forexample, given a comparison graph G the number of different acyclic orientations of G givesan upper bound on the number of possible answers. Given the fact that it does not take anycomparisons to identify G (up to isomorphism) and G has at most ≤ Q v ∈ V ( d v + 1) ≤ n n [20]number of acyclic orientations the ITB of O ( n log n ) in the standard comparison tree model istoo week for this problem. The matter is further complicated if one is also given the guaranteethat the graph G is sortable . We say G is sortable G can be totally sorted. This restriction furtherreduces the number of possible answers for graphs with small number of edges. For example if G has ≤ n − G must give a hamiltonian path and G has ≤ n − G to be arbitrary and notnecessarily sortable. Hence by sorting G we mean determining the orientations of the edges of G such that the resulting partial order (which is unique) has the maximum number relations.In this paper we propose the first non-trivial deterministic algorithm under the probe com-plexity model as well as a randomized algorithm. The results are expressed in terms of n and q . Expressing the results in terms the number of forbidden edges fits naturally with the prob-lem. First of all q and w are related. Let P G be the poset found after sorting G . We have q ≥ P G ≥ (cid:0) w (cid:1) . Hence, w = O ( √ q ). Although we cannot directlycompare the probe complexity used in this paper with the query complexity in [16] but it gives abetter sense of the relatedness of the two models. Secondly, in the absence of any other structuralproperties of the input graph G , q gives a good indication of how difficult it is to sort G . Forexample, when q = O (log n ), it is easy to see that one can sort in O ( n log n ) total time. Todo this we pick an arbitrary pair of non-adjacent vertices and take out one of them, removingit from the graph. We do the same thing with the remaining graph until the graph remainingis a clique. It is clear that we had to take out at most O (log n ) vertices. Then we sort thisgraph with O ( n log( n )) comparisons and merge the vertices we had remove previously by prob-ing all the remaining undirected edges, which is at most O ( n log n ). On the other extreme, if | E | = (cid:0) n (cid:1) − q = O ( n ) then it can be shown that we need to make Ω ( | E | ) probes to determinethe partial order, since the complete bipartite graph K ( A, B ) with | A | ≪ | B | has many acyclicorientations [19, 20]. So in this case one has to probe most of the allowed edges.In the context of randomized algorithms, this problem has been studied in [1,15]. The authorsin [1] proposed a randomized algorithm that sorts G with a probe complexity of e O ( n / ) with highprobability . However their implementation uses as a sub-routine a poly-time uniform samplingalgorithm to sample points from a convex polytope [21]. The authors did not discuss the exact By high probability we mean that the probability tends to 1 as n → ∞ .orting Under 1- ∞ Cost Model 3 bound on the total complexity in their paper. At each step the algorithm either finds a balancingedge or finds a subset of elements that can be sorted quickly. For an arbitrary G it is notguaranteed that a balancing edge always exists. However, when G is the complete graph therealways exists a balancing edge that reduces the number of linear extension at-least by a factorof 8 /
11 [13].
The main contributions of this paper are as follows: – Given a comparison graph G we propose a deterministic algorithm that sort G with O (( q + n ) log n ) probes. The total complexity of our algorithm is O ( n + q ω/ ), where ω ∈ [2 , . G and use its elementsto determine a good pivot. This is then applied recursively to induced subgraphs of G togenerate a collection of partial orders. We then merge these partial orders in the final step. – We propose a randomized algorithm which sorts G with O ( n / √ n + q + n √ q ) probes withhigh probability. We use a random graph model for this purpose. The method uses onlyelementary techniques and unlike in [1] has a total run time of O ( n ω ) in the worst case. – When G is a random graph with edge probability p we show that one can sort G with highprobability using only e O (min ( n / , pn )) probes.The rest of this paper is organized as follows: in section 1.2 we introduce some definitions andlemmas for later use. Section 2 details the proposed deterministic algorithm. In section 3 weintroduce the randomized algorithm and its extension to random graphs. Recall G ( V, E ) is the input graph on the set V of elements to be sorted. A pair of vertices ( u, v )can be compared if ( u, v ) ∈ E , otherwise, we say the pair is forbidden and is in E f . The graph G is given to us by our adversary. Let G i be the graph after i -edges have been oriented and P i bethe associated partial order. We denote the degree of a vertex v by d ( v ) and n ( v ) = n − − d ( v )is the number of vertices that are not adjacent to v . The set of neighbors of a vertex v is denotedby N ( v ). We use the notation E ( A, B ) we denote the set of edges between the sets of vertices
A, B ⊂ V . We also define the little- o notation to remove any ambiguity from our exposition. Definition 1. If f ( n ) ∈ o ( g ( n )) then f ( n ) ∈ O ( g ( n )) but f ( n ) Ω ( g ( n )) . Lemma 1.
Let { f ( n ) , f ( n ) , ..., f k ( n ) } be a finite set of non-negative monotonically increasingfunctions in n such that:1. ∀ i f i ( n ) ∈ o ( g ( n )) P i f i ( n ) ≤ cg ( n ) If F ( n ) = P i f i ( n ) then F ( n ) ∈ o ( g ( n )) .Proof. See appendix.
Lemma 2.
Let T ( n ) = P ki =1 T ( n i ) + f ( n ) where P i n i ≤ δn for some < δ < and f ( n ) ∈ o ( n ) . Then, T ( n ) ∈ o ( n ) .Proof. See appendix. An edge in G revealing whose orientation is guaranteed to reduce the number of linear extension ofthe current partial order by a constant fraction. The pair of vertices incident to this edge is referredto as a balancing pair . I Banerjee, D Richards First we look at a simple case where q = O ( n ). We will use some of the main ideas fromthis algorithm to extend it to the general case. This initial algorithm will have a worse probecomplexity than the main algorithm. Assume q ≤ cn for some constant c . Let R = { v ∈ V | n ( v ) > c } for some constant c . Then | R | ≤ (2 c/c ) n . We choose c = 4 c . This is obvious from the fact that P v n ( v ) ≤ cn . Let S = V \ R and G [ S ] be the induced subgraph generated by S . We have | S | ≥ n/ v ∈ S then n ( v ) ≤ c . Claim 1.
There exists a subset X ⊂ S such that | X | ≥ n/ c + 1) and G [ X ] is a completegraph.Proof. Let us construct X explicitly. We start with X = u , where u is an arbitrary vertex in S.We pick successive vertices from S iteratively. Let v be last vertex to be added to X . Since v has at least n − c neighbors, whenever we pick a neighbor of v from S to add to X we loose atmost c + 1 vertices (which include the vertex we picked). Hence if we pick neighbors of v thesize of X is at least | S | / ( c + 1) ≥ n/ c + 1).Clearly the above procedure runs in O ( n ) time and makes no comparisons. Now we are readyto describe our algorithm. The main algorithm is recursive and we have two levels of recursion.We shall break the algorithm into several steps. Initial Sorting:
Given the input graph G , let X be a clique, with | X | ≥ n/ c + 1) (Claim1). Let Y = V \ X . Note that | Y | ≤ n − n/ c + 1) = (8 c + 1 / c + 2) n . Now we sort X using O ( n log n ) comparisons as G [ X ] is a complete graph. We can use a standard comparison basedsorting algorithms for this purpose. Now we have two possibilities:Case 1: If | Y | = o ( n ) , then we probe all edges of G [ Y ] and G [ Y, X ], where G [ Y, X ] is the inducedbipartite graph generated by the sets Y and X . Then we take the transitive closure of theresulting relations, which does not need any additional probes. It can be easily seen thatthe number of probe made in the previous step is o ( n ). For the sake of contradiction if weassume that it is not so then | X || Y | + | Y | / ≥ dn for some d . Which implies | Y | ≥ dn ,since | X | + | Y | / ≤ n . But then, | Y | = Ω ( n ), which is not true according to our earlierassumption. So, in this case we would have sorted V by making only o ( n ) probes.Case 2: Otherwise | Y | ≥ δn , for some constant δ . In this case we recursively partition Y based onelements from X . We call this the partition step. Partition step:
We will recursively partition both X and Y . To keep track of the currentpartition depth we rename X to X and Y to Y . We pick m the median of X (after X is sorted). Since X ⊂ S we have n ( m ) ≤ c . So m will be comparable to all but at most c elements of Y . Let, A = { v ∈ Y | v ∈ N ( m ) } and B = Y \ A . Note | B | ≤ c . Now let U be the subset of A whose elements are ≥ m and the set L accounts for the rest of A \ m . Let X and X be the elements of X that are < and ≥ to m respectively. We recursively partition the sets U and L usingthe medians of X and X .The B -sets are kept for later processing. We rename the sets U and L to Y and Y . So, the pairs ( X , Y ) and ( X , Y ) are processed as above generatingthe sets A , A , B and B . We continue doing this until the size of the X -set is ≤ c , where c is some constant. At this point we don’t know the size of the Y -set paired with it. There aretwo cases we need to consider: Note that “ | Y | = o ( n )” is not an algorithmic test. We use it in this algorithm to establish a frameworkfor the second algorithm, which uses a traditional test.orting Under 1- ∞ Cost Model 5
Case 1: | Y | = o ( n ) Then we probe all the edges of G [ Y ] and G [ X, Y ] which uses at most c | Y | + (cid:0) | Y | (cid:1) number of comparisons.Case 2: | Y | ≥ δn . Then we have | Y | ≥ δn for constant δ . Hence the graph G [ Y ] can have at most ≤ ( c/δ ) | Y | missing edges. This satisfies our initial premise that the number of missing edgesin G [ Y ] is linear in the number of vertices. Hence we can apply our initial strategy recursively.That is we first find a large enough clique (which according to Claim 3 must exist) and thenuse it to partition the rest of the set Y .Let us visualize using a partial recursion tree T (see Fig.1 below). We shall call T the partialrecursion tree for reasons soon to be clear. At the root we have the pair ( X , Y ). It has twochildren node ( X , Y ) and ( X , Y ) each having two children of their own and so on. Now ateach level, the size of the X -set gets halved. So, the number of levels in T is at most O (log n ).However, the Y -sets need not get divided with equal proportions. So, at the frontier (the deepestlevel) we will have nodes of the above two types, depending on the size of their corresponding Y -sets. Let the collection of these frontier nodes be partitioned in two sets Φ and Ψ correspondingto case 1 and case 2 respectively.We can conclude that the total number of probes needed to compute all relations in Φ is o ( n ). This follows from Lemma 1. Here we can map the size of the Y -sets of the nodes in thecollection Φ to the functions f i ( n ). We know that the total elements in the union of these Y -setsis ≤ | Y | ≤ (8 c + 1 / c + 2) n . The total number of probes will be F ( n ) in worst case. What isthe total number of probes on the internal nodes of T ? We know that in the internal nodes wecompare the median of the X -set with the elements of the A -set, which takes | A | probes. Sinceunion of these A -sets cannot exceed the total number of vertices in G ( n ), at each level of T wedo at most O ( n ) probes, totaling to O ( n log n ) probes over all the internal nodes.Unlike the nodes in Φ , the nodes in Ψ recursively calls the initial strategy using the inputgraph G [ Y ]. Let the probe complexity of our initial strategy be Q ( n ). Then the recursion for Q is as follows: Q ( n ) = | Ψ | X i =1 Q ( n i ) + o ( n )Here we assume that the nodes in Ψ are indexed according to some arbitrary order. We can solvethis recurrence using Lemma 2 giving Q ( n ) ∈ o ( n ), since P | Ψ | i =1 n i ≤ (8 c + 1 / c + 2) n . Note herethat | Ψ | is bounded by a constant since the size of Y -sets are in Ω ( n ).We call ˆ T the full tree. All leaf nodes in ˆ T are in Φ . It is straightforward to show that ˆ T has O (log n ) levels. Since any of the leaf nodes of T has | Y | ≤ βn (where β = (8 c + 1 / c + 2)), itssubtree in ˆ T can have at most α log βn = α log n − αβ levels, and any of its leaves having atmost α log n − αβ levels and so on for some constant α . Merge step:
Once we have completed building ˆ T we proceed with the final stage of our algo-rithm. Recall that during the forward partition step we had generated many of these B -sets inthe internal nodes of ˆ T . Now we start from the leaves of ˆ T and proceed upwards. Each pair ofleaf nodes l, r sharing a common parent p , sends a partial order to it them (computed as in case1). When we merge this two partial orders we know that no extra probe is needed since theyhave already been split by the median of the X -set of p . What remains is to probe all edgesbetween the B -set in p and elements in this partial order (which constitutes the set of elements A ∪ X of the node p ) as well as the edges in G [ B ]. Then we pass the resulting partial order tothe parent of p , and so on. Since the size of the B -sets are bounded by c (at any level in ˆ T ),total number of probes we make is then ≤ c P i ( | A i | + | X i | + c ). The sum is taken over all thenodes in that level. Hence this is bounded by c n , so at each level we do at most O ( n ) probesin the backward merging step. Since there are at most O (log n ) levels, it totals to O ( n log n )additional probes. Adding this to the probe cost of partitioning in the forward step does noteffect the total probe complexity, which was o ( n ). The final step is to compute the transitiveclosure of the resulting set of relations, which can be done without any additional probing. Sincecomputing the transitive closure is equivalent to boolean matrix multiplication [23] the totalcomplexity is O ( n ω ). I Banerjee, D Richards U L B X X m U L B X X m { { } { ∈ Ψ ∈ Ψ ∈ ΨSORT X T ˆ T T T T T T U L B X X m Fig. 1.
Visualizing the steps. At the bottom of T the shaded boxes represents the Φ -nodes and the bluerectangles the Ψ -nodes. The outer dashed triangle represents the full tree ˆ T . The tree ˆ T is created duringthe partitioning step and in the merge step we start from the deepest leaves of ˆ T and move upwards. We will define the sets R and S analogously to section 2.1. We have, R = { v ∈ V | n ( v ) >c q/n } for some constant c . With c = 4, we get | R | ≤ δ n where δ ≤ /c = 1 /
2. Hence | S | ≥ (1 − δ ) n ≥ n/
2. Now we will apply Claim 1 successively to construct a “big-enough” set X ⊂ S which we will use to find an approximate median of V . This set X consists of disjointsubsets X i such that G [ X i ] is a clique. Constructing X : Let us define S i = S \ S ij =1 X j . We construct the first clique X ⊂ S usingthe method detailed in Claim 1. There are two cases:Case 1 q < n : In this case we can show that | X | ≥ ( n/ / ( c q/n + 1) ≥ n/
10. We take the first n/
10 elements and keep the rest for the second round. Now we construct the second clique X from S which has at least 2 n/
25 vertices. We let X = X ∪ X . Hence X has at least9 n/
50 vertices.Case 2 q ≥ n : In this case we have | X | ≥ ( n/ / ( c q/n + 1) ≥ n / q . Again we take | X | =(1 / n /q discarding some vertices if necessary. Similarly we construct X ⊂ S . It can beshown that | X | ≥ ( n / q )(1 − n/ q ) and we keep ( n / q )(1 − n/ q ) vertices in X andthe rest are discarded to be processed the next round. In general for the r th clique X r wehave | X r | ≥ ( n / q )(1 − n/ q ) r − . Now we let X = S ri =1 X i . We will show that | X | ≥ δ n for some constant δ >
0. We let r = 5 q/n + 1. Then we have | X r | ≥ ( n / q )(1 − n/ q ) r − ≥ ( n / q )(1 − n/ q ) q/n > n / q since q ≥ n . Hence, | X | = P ri =1 | X i | ≥ r | X r | ≥ (9 / n , giving δ = 9 /
50. Now for each X i (1 ≤ i ≤ r ) we keep a subset Y i of size | X r | and throw away the rest. Clearly, for each i , theinduced sub-graph G [ Y i ] is also a clique. Let Y = S ri =1 Y i . We also have | Y | ≥ (9 / n . Computing an approximate median of V : We shall compute an approximate median withrespect to all the vertices (the set V ) and not just the set S . We will find a median element thatdivides the set V in constant proportions. This can be done easily using the set Y . For each Y i wefind its median using Θ ( | Y i | ) probes since G [ Y i ] is a complete graph. Let this median be m i and orting Under 1- ∞ Cost Model 7 M be the set of these r medians. Since m i ∈ S , n ( m i ) ≤ q/n . We define the upper set of m ∈ M with respect to a set A ⊂ V ( m may not be a member of A ) as U ( m, A ) = { a ∈ A | a > m } .Similarly we define the lower set L ( m, A ). We want to compute the sets U ( m, Y ) and L ( m, Y ).However, m may not be neighbors of all the elements in Y . So we compute approximate upperand lower sets by probing all the edges in E ( { m } , Y \ { m } ). These sets are denoted by e U ( m, Y )and e L ( m, Y ) respectively. It is easy to see that there exists some m ∈ M which divides Y intosets of roughly equal sizes (their sizes are a constant factor of each other). In fact the median of M is such an element. However the elements in M may not all be neighbors of each other hencewe will approximate m using the ranks of the elements in M with respect to the set Y (whichis | e L ( m, Y ) | ). Next we prove that the element m ∗ is an approximate median of M , picked usingthe above procedure, is also an approximate median of Y . Claim 2.
The element m ∗ picked as described above is an approximate median of Y .Proof. First we show that the median of M is an approximate median of Y . This can beeasily verified. Let us take the elements in M in sorted order ( m , ..., m r ), so the medianof M is m ⌊ r/ ⌋ . Now L ( m ⌊ r/ ⌋ , Y ) = S ⌊ r/ ⌋ i =1 L ( m i , Y i ). Since, the sets Y i are disjoint and L ( m i , Y i ) ≥ | X r | /
2, we have | L ( m ⌊ r/ ⌋ , Y ) | ≥ | X r | r/ | U ( m ⌊ r/ ⌋ , Y ) | ≥ | X r | r/
4. Hence m ⌊ r/ ⌋ is an approximate median of Y . Now weshow that | | L ( m ∗ , Y ) | − | L ( m ⌊ r/ ⌋ , Y ) | | < q/n . Consider the sorted order of elements in M according to | e L ( m ∗ , Y ) | . Since each element in m ∈ M has at most 4 q/n missing neighbors in Y , we have | | e L ( m, Y ) | − | L ( m, Y ) | | < q/n . So the rank of an element in the sorted order is atmost 4 q/n less than its actual rank. Thus an element m ∗ picked as the median of M using itsapproximate rank | e L ( m, Y ) | cannot be more than 4 q/n apart from m ⌊ r/ ⌋ in the sorted order of Y . Hence, | L ( m ∗ , Y ) | ≥ | X r | r/ − q/n ≥ n/ − q/n ≥ n/
40 (1)whenever n ≥ q . In an identical manner we can show that | U ( m ∗ , Y ) | ≥ n/
40. Hence, m ∗ isan approximate median of Y . When q < n we just take m ∗ as the median with the higher | e L ( · , Y ) | value, which guarantees | L ( m ∗ , Y ) | ≥ n/
40 whenever n ≥ q/
13. So we take n ≥ q tocover both the cases.It immediately follows that m ∗ is also an approximate median of V with both | L ( m ∗ , V ) | and | U ( m ∗ , V ) | lower bounded by n/
40. Lastly, we note that the above process of computing anapproximate median makes Θ ( q + n ) probes. This follows from the fact that computing themedians makes Θ ( n ) probes in total and for each of the ≤ q/n + 1 medians we make O ( n )probes. A divide-and-conquer approach:
Now that we have computed an approximate median of V we proceed with an recursive approach. Let m ∗ be the median. As in section 3.1 we partition V into three sets U , L and B . The U and L are the upper and lower sets with respect to m ∗ . B is the set of vertices that do not fall into either, that is, they are non-neighbors of m ∗ . Since m ∗ ∈ S we have | B | ≤ q/n . We recursively proceed to partially sort the sets U and L with thecorresponding graphs G [ U ] and G [ L ] and keep B for later processing (as we did in the mergingstep previously). Like before we can imagine a recursion tree T . Let E f P be the set forbiddenedges in G [ P ]. We take n P = | P | and q P = | E f P | . For each node P ∈ T there are two cases:Case 1: When n P ≥ q P , we recursively sort P . In this case we can guarantee that the approximatemedian m ∗ P of P will satisfy equation (1). That is both | L ( m ∗ P , P ) | and | U ( m ∗ P , P ) | is ≥ n P / G [ P ]. In this case P will become a leaf node in T .It can be easily seen that the depth of the recursion tree is bounded by O (log n ) since at eachinternal node P of T we pass sets of constant proportions (where the size of the larger of thetwo set is upper bounded by (39 / n P ) to its children nodes. I Banerjee, D Richards
Merge Step:
In this step we start with the leaves of T and proceed upwards. A parent node P gets two partial orders from its left and right children respectively. Then it probes all theedges between its B -set and these partial orders to generate a new partial order and pass it onto its own parent. This step works exactly as the “merge step” of the previous algorithm. Onlydifference is that the B -sets here may not be of constant size but of size ≤ q/n . Probe Complexity:
We can determine the probe complexity by looking at the recursion tree T . First we compute it for the forward partition step. At each internal node of T we compute aset of medians and pick one element from it appropriately chosen. Then we partition the set ofelements at the node by probing all edges between the selected element and rest of the elementsin the node. As mentioned before this only takes Θ ( q P + n P ) probes for some internal node P . Weassume that all the leaves of T are at the same depth, otherwise we can insert internal dummynodes and make it so. At each level of T the sum total of all the vertices in every node is ≤ n andthe sum total of the forbidden edges is ≤ q . Hence we do O ( q + n ) probes at any internal level of T . So for a total of O (log n ) internal levels in T the number of probes done is (( q + n ) log n ) inthe forward partition step. If P is a leaf node then we probe all edges in G [ P ]. There are at most (cid:0) n P (cid:1) − q P edges in G [ P ]. Since P is a leaf node, according equation 1, n P < q P . Hence wemake (cid:0) n P (cid:1) − q P = O ( q P ) probes. Summing this over all the leaves gives a total of O ( q ) probes.Hence the total probe complexity during the forward step is O (( q + n ) log n ).Now we look at the merging step. Merging happens only at the internal nodes. Lets lookat an arbitrary internal level of T . At each node P of this level we probe all the edges in E ( B P , U P ∪ L P ∪ m ∗ P ) and in G [ B P ]. Note that we do not have to make any probes between U and L as they were already separated by the approximate median m ∗ P . Hence the total numberof probes made in this node is ≤ ( | U P | + | L P | + | B P | + 1) | B P | ≤ ( n p )(4 q P /n p ) ≤ q p . Summingover all the nodes at any given level gives us O ( q ) as the probe complexity per level. So thetotal probe complexity in the merging stage is O ( q log n ). Hence, combining the probes madeduring the partition step and the merge step we see that the total probes needed to sort V is O (( q + n ) log n ). Total Complexity:
Now we look at the total complexity of the previous procedure. Again theanalysis is divided into forward step and the merge step. In the forward step at each node P weperform O ( n p ) operations. This includes computing the degrees, finding the cliques, computingthe approximate median. So at any level of T , regardless of it being an internal level or not, weperform O ( n ) operations. Hence it totals to O ( n log n ) operations in the forward step. Howeverthis is a conservative estimate and we can remove the log n factor as argued below: we can definethe recurrence for the forward computation as, T ( n ) = ( T ( n/
40) + T (39 n/
40) + O ( n ) n ≥ qO ( q ) Otherwise (2)This follows from the previous discussion. If we don’t recurse on a node we guarantee that n p < q p for that node. Hence, we have T ( n ) = O ( n + q ) using the Akra-Bazzi method [22].In the merge step, we only make O ( q p ) comparisons at any given node. We compute transitiveclosures only at the leaves. However for any leaf P we have n P < q P . Hence computing thetransitive closure of G [ P ] takes O ( q ω/ P ) time. Hence, the total complexity of the above procedureis O ( n + q ω/ ). We summarize the results in this section with the following theorem: Theorem 1.
Given a graph G ( V, E ) of n vertices having q forbidden edges, one can computethe partial order of V with O (( q + n ) log n ) comparisons and in total O ( n + q ω/ ) time.Proof. Follows from the discussions in this section.
In this section we look at a more direct way of sorting by making random probes. The proposedmethod is inspired by the literature on two-step oblivious parallel sorting [10, 11] algorithms, in orting Under 1- ∞ Cost Model 9 particular on a series of studies by Bollob´as and Brightwell showing certain sparse graphs can beused to construct efficient sorting networks [3, 12]. It was shown that if a graph satisfies certainproperties then probing its edges and taking the transitive closure of the resulting set wouldyield large number of relations. Then we just probe the remaining edges that are not oriented,which is guaranteed (with high probability) to be a “small” set.The main idea is as follows: Let H n be a collection of undirected graphs on n vertices havingcertain properties. A transitive orientation of a graph H ( V, E ) ∈ H n is an ordering of V and theinduced orientation of the edges of H based on that ordering. Let σ be an ordering on V and P ( H, σ ) be the partial order generated by this ordering σ on H . It is a partial order since H may not be sortable. Let P = P ( H, σ ) and t ( P ) be the number of incomparable pairs in P . Wewant H to be such that t ( p ) is small. If that is the case then P will have many relations and if H is sparse then we can probe all the edges of H and afterwards we will be left with probingonly a small number of pairs. These are pairs which were not oriented during the first roundof probing and after the transitive closure computation. A graph H is useful to our purpose ifevery transitive orientation of H results in many relations. We want to find a collection H n suchthat every graph in it is useful with high probability.We extend the results in [3,12] to show that a collection of certain conditional random graphsare useful, with high probability. In our case this random graph will be a spanning subgraph ofthe input graph G . Here we recall an important result from [3] which we will use in our proof. Theorem 2 (Theorem 7 in [3]) . If G is any graph on n vertices and G satisfies the followingproperty:Q1: Any two subsets A, B of vertices having size l have at least one edge between them.Then, the number of incomparable pairs in P ( G, σ ) is at most O ( nl log l ) for any σ . The input graph G is chosen by our adversary. However, we show that any random spanningsubgraph of G with an appropriate edge probability will satisfy Q1 with high probability. Let H n,p ( G ) be a random spanning subgraph of G , where H n,p ( G ) has the same vertex set as G anda pair of vertices in H n,p ( G ) has an edge between them with probability p if they are adjacentin G , otherwise they are also non-adjacent in H n,p ( G ). All we need to prove is that any randomspanning subgraph H n,p ( G ) given G with n -vertices and edge probability p will satisfy Q1 withhigh probability. Since G has at most q forbidden edges any two subsets of vertices A, B (notnecessarily distinct) of size l must have at least (cid:0) l (cid:1) − q edge between them. Let, E AB be theevent that the pair ( A, B ) is bad (they have no edges between them), then the probability S n,p that there exists a bad pair is: S n,p := P ( X i,j E A i B j ) ≤ X i,j P ( E A i B j ) ≤ X i,j (1 − p ) e ( A i ,B j ) (3)where the sum is taken over all such (cid:0) nl (cid:1) pairs of subsets, and the number of edges between thetwo sets A and B in G is e ( A, B ) ≥ (cid:0) l (cid:1) − q . So we have, S n,p ≤ (cid:18) nl (cid:19) (1 − p )( l ) − q ≤ (cid:18) nl (cid:19) e − p ( ( l ) − q ) Since, e − x ≥ − x ≤ (cid:16) enl (cid:17) l e − p ( ( l ) − q ) ≤ exp(2 l (log en/l ) − p ( (cid:18) l (cid:19) − q ))Hence S n,p → n → ∞ whenever exp(2 l (log en/l ) − p ( (cid:0) l (cid:1) − q )) = o (1). Given q < (cid:0) n (cid:1) it isalways possible to find appropriate values for p and l as functions of q and n such that S n,p = o (1).Given some value for the pair ( p, l ), we see that in the first round we make O ( pn ) probes withhigh probability and in the second round O ( nl log l ) probes again with high probability. So thetotal probe complexity is e O ( pn + nl ). With some further algebra it can be shown that this is e O ( n / √ q + n + n √ q ). We summarize this section with the following theorem: Theorem 3.
Given a graph G on n vertices and q forbidden edges one can determine the partialorder on G with high probability in two steps by probing only e O ( n / √ q + n + n √ q ) edges in totaland in O ( n ω ) time.Proof. Follows from the preceding discussions. G is a Random Graph The above technique can easily be extended for the case when the input graph is random. Let G n,p be the input graph having n -vertices and an uniform edge probability p . For such a graphwe can use equation (3) to bound S n,p as follows: S n,p ≤ (cid:18) nl (cid:19) (1 − p ) l ≤ exp( − pl + 2 l log n )Hence, we can choose any l > n/p such that S n,p → n → ∞ . Let l = 3 log n/p .Using Theorem 2 we have t ( G n,p ) = e O ( nl ) = e O ( n/p ). Since G n,p has pn / p when t ( G n,p ) = pn / e O (1 / √ n ). Let this be ˆ p . Hence if p > ˆ p , we can sort by making only e O ( n / ) comparisons. Since given G n,p we can construct aninduced subgraph G n, ˆ p and use it as the random graph in our previous construction. Otherwisewe just probe all the edges which makes O ( pn ) comparisons. Thus we can sort G n,p with at most e O (min ( n / , pn )) comparisons with high probability. Hence, we get an elementary techniqueto sort a random graph with at most e O ( n / ) comparisons. The algorithm in [1] has a slightlybetter bound of e O ( n / ) comparisons. However, the total runtime of the algorithm in [1] is onlypolynomially bounded when p is small. In our algorithm we need compute the transitive closureonly twice making it run in O ( n ω ) total time. Concluding Remarks
In this paper we study the problem of sorting under non-uniform comparison costs, where costsare either 1 or ∞ . This cost structure is non-monotone resulting in additional complexity. Theresults presented here only uses elementary techniques, yet achieving non-trivial bounds on probecomplexity. Further, we present strong evidence that the complexity of sorting V is dependent oncertain properties of the input graph, in particular the number of forbidden edges q . We derivean non-trivial upper bound O (( q + n ) log n ) for the probe complexity. The total complexity ofour algorithm is bounded by O ( n + q ω/ ). Since the lower bound for the total complexity of theproblem is Ω ( n ), module fast matrix multiplication, the proposed algorithm is almost optimalin terms of the total complexity. We also present a randomized algorithm for the problem whichuses e O ( n / √ q + n + n √ q ) probes with high probability. When the input graph is random thisalgorithm requires only e O ( n / ) probes again with high probability. References
1. Huang, Z., Kannan, S., Khanna, S. (2011, October). Algorithms for the generalized sorting problem.In Foundations of Computer Science (FOCS), 2011 IEEE 52nd Annual Symposium on (pp. 738-747).IEEE.2. Cardinal, J., Fiorini, S. (2013). On generalized comparison-based sorting problems. In Space-EfficientData Structures, Streams, and Algorithms (pp. 164-175). Springer Berlin Heidelberg.3. Bollob´as, B., Brightwell, G. (1988). Transitive orientations of graphs. SIAM Journal on Computing,17(6), 1119-1133.4. Charikar, M., Fagin, R., Guruswami, V., Kleinberg, J., Raghavan, P., Sahai, A. (2000, May). Querystrategies for priced information. In Proceedings of the thirty-second annual ACM symposium onTheory of computing (pp. 582-591). ACM.5. Kahn, J., Saks, M. (1984). Balancing poset extensions. Order, 1(2), 113-126.orting Under 1- ∞ Cost Model 116. Fredman, M. L. (1976). How good is the information theory bound in sorting?. Theoretical ComputerScience, 1(4), 355-361.7. Alon, N., Blum, M., Fiat, A., Kannan, S., Naor, M., Ostrovsky, R. (1994, January). Matching nutsand bolts. In SODA (pp. 690-696).8. Gupta, A., Kumar, A. (2001, October). Sorting and selection with structured costs. In Foundationsof Computer Science, 2001. Proceedings. 42nd IEEE Symposium on (pp. 416-425). IEEE.9. Koml´os, J., Ma, Y., Szemerdi, E. (1998). Matching nuts and bolts in O (n log n) time. SIAM Journalon Discrete Mathematics, 11(3), 347-372.10. Ajtai, M., Komls, J., Steiger, W., Szemerdi, E. (1989). Almost sorting in one round. Advances inComputer Research, 5, 117-125.11. Bollob´as, B., Rosenfeld, M. (1981). Sorting in one round. Israel Journal of Mathematics, 38(1-2),154-160.12. Bollob´as, B., Brightwell, G. (1987). Graphs whose every transitive orientation contains almost everyrelation. Israel Journal of Mathematics, 59(1), 112-128.13. Kahn, J., Kim, J. H. (1995). Entropy and sorting. Journal of Computer and System Sciences, 51(3),390-399.14. Janson, S. (2004). Large deviations for sums of partly dependent random variables. Random Struc-tures & Algorithms, 24(3), 234-248.15. Angelov, Stanislav, Keshav Kunal, and Andrew McGregor. ”Sorting and selection with randomcosts.” LATIN 2008: Theoretical Informatics. Springer Berlin Heidelberg, 2008. 48-59.16. Chatterji S.D.(1966) The Number of Topologies of n points, Kent State University, NASA TechnicalReport.17. Daskalakis, C., Karp, R. M., Mossel, E., Riesenfeld, S. J., Verbin, E. (2011). Sorting and selectionin posets. SIAM Journal on Computing, 40(3), 597-622.18. U. Faigle and Gy. Tur´an. (1988) Sorting and Recognition Problems for Ordered Sets, SIAM J.Comput. 17(1): 100113.19. Kahale, N., Schulman, L. J. (1996). Bounds on the chromatic polynomial and on the number ofacyclic orientations of a graph. Combinatorica, 16(3), 383-397.20. Goddard, Wayne, et al. ”Optimal randomized algorithms for local sorting and set-maxima.” SIAMJournal on Computing 22.2 (1993): 272-283.21. Dyer, M., Frieze, A., Kannan, R. (1991). A random polynomial-time algorithm for approximatingthe volume of convex bodies. Journal of the ACM (JACM), 38(1), 1-17.22. Akra, M., Bazzi, L. (1998). On the solution of linear recurrence equations. Computational Opti-mization and Applications, 10(2), 195-210.23. Savage, J. E. (2008). Models of Computation: Exploring the power of computing. CC-3.0. BY-NC-ND, electronic edition. Appendix
Proof of Lemma 1:
Let, { f ( n ) , f ( n ) , ..., f k ( n ) } be a finite set of non-negative monotonically increasing functionsin n such that:1. ∀ i f i ( n ) ∈ o ( g ( n ))2. P i f i ( n ) ≤ cg ( n )If F ( n ) = P i f i ( n ) Then F ( n ) ∈ o ( g ( n )). Proof.
First we prove F ( n ) = O ( g ( n )). Clearly,( X i f i ( n )) ≤ c g ( n ) X i f i ( n ) + 2 X i,j f i ( n ) f j ( n ) ≤ c g ( n ) F ( n ) ≤ c g ( n )Now we prove F ( n ) = Ω ( g ( n )): assume that F ( n ) ∈ Ω ( g ( n )), then there exists someconstant ˆ c such that, F ( n ) ≥ ˆ cg ( n ) whenever n ≥ n . Now let f i ( n ) ≤ c i g ( n ) whenever n ≥ n ( c i ). Since, f i ( n ) ∈ o ( g ( n )) we can pick this c i ’s arbitrarily and independent of eachother. Now, for n ≥ max( n , n ) (where n = max i ( n ( c i ))) we have, X i f i ( n ) ≥ ˆ cg ( n ) X i c i ≥ ˆ c This contradicts the fact that c i ’s can be assigned arbitrary values independent of each other.That is, not all f i ( n ) will satisfy the condition f i ( n ) ∈ o ( g ( n )) simultaneously. Hence, F ( n ) = Ω ( g ( n )). Proof of Lemma 2:
Let, T ( n ) = P ki =1 T ( n i ) + f ( n ) where P i n i ≤ δn for some 0 < δ < f ( n ) ∈ o ( n ). Then, T ( n ) ∈ o ( n ). Proof.
Let as assume T ( n ) = Ω ( n α ) for some α ≥
1. Otherwise we are done. Hence, P ki =1 T ( n i ) ≤ T ( P ki =1 n i ) = T ( δn ). So, the recurrence becomes, T ( n ) ≤ T ( δn ) + f ( n ). Using Master theoremwe see that the case 3 applies here, which gives, T ( n ) = Θ ( f ( n )) = o ( n2