Upper bounds for sorting permutations with a transposition tree Bhadrachalam Chitturi Department of Computer Science, Amrita Vishwa Vidyapeetham University, Amritapuri Campus, Clappana P.O., Kollam 690525, Kerala, India
[email protected]
Abstract. An upper bound for sorting permutations with an operation estimates the diameter of the corresponding Cayley graph and an exact upper bound equals the diameter. Computing tight upper bounds for various operations is of theoretical and practical (e.g. interconnection networks, genetics) interest. Akers and Krishnamurthy gave a Ω(n! n2 ) time method that examines n! permutations to compute an upper bound, f (Γ ), to sort any permutation with a given transposition tree T , where Γ is the Cayley graph corresponding to T . We compute two intuitive upper bounds γ and δ ′ for the same in O(n2 ) time each by working solely with the transposition tree. Recently, Ganesan computed β, an estimate of the exact upper bound for the same, in O(n2 ) time. Our upper bounds are tighter than f (Γ ) and β, on average and in most of the cases. For a class of trees, we prove that the new upper bounds are tighter than β and f (Γ ).
Key words: Cayley graphs, diameter, graph algorithms, greedy algorithms, permutations, sorting, strings, transposition trees, upper bound.
1
Introduction
A transposition tree T is a spanning tree over its n vertices i.e. VT = (1, 2, . . . n) [19]. We denote the symmetric group of all permutations of length n by Pn . Let π ∈ Pn be the permutation that needs to be sorted. Let ET be the set of edges of T . Let π(i) and VTi (or simply i) denote ith symbol of π and the ith vertex respectively. The symbol π(i) resides at i and (i, j) ∈ ET where ET is the set of edges of T signifies that π(i) and π(j) can be swapped. Each such swap is a move. The objective is to sort π with the minimum number of moves. The sorted permutation is In = (1, 2, . . . n) where ∀i π(i) = i. In a spanning tree, there is a path between any pair of vertices. That is, in T , ∀i,j , by a sequence of moves π(i) and π(j) can be swapped. Thus, T generates the symmetric group [30]. 12 1
2
Cite as: B. Chitturi. Upper bounds for sorting permutations with a transposition tree. DMAA (5)(1), 2013. LNCS style is used.
2
Bhadrachalam Chitturi
Given a group P and a set of generators G for the group, the Cayley graph Γ of P with respect to G is a graph with vertex set P , and an arc from a to b implies that ∃g ∈ G | ag = b. Given an operation Ψ and n, Ψ is generic, say a reversal, and a generator of Ψ is specific, i.e. a reversal of the sublist from i1 . . . i2 where 1 ≤ i1 ≤ i2 ≤ n for specific values of i1 and i2 . Thus, a reversal has O(n2 ) generators. For a given T , ET constitutes the set of n − 1 generators, where n − 1 = |ET |, the cardinality of ET . A move is an application of a particular generator. For a given operation Ψ and n, an upper bound specifies a value k where any π ∈ Pn can be sorted by at most k moves. Conversely, any vertex in Γ can be reached from any other vertex by traversing at most k edges. Ψ and n are specified by the context. The length of a shortest path from vertex φ ∈ Γ to vertex ι ∈ Γ is the distance between φ and ι; it is denoted by dΓ (φ, ι). The diameter of Γ , i.e. diam(Γ ) = arg max∀φ,ι∈Γ dΓ (φ, ι). Likewise, the length of a shortest path from VTi to VTj in T is the distance between VTi and VTj denoted by dT (i, j). The diameter of T is denoted by diam(T ). In this article, Γ is the corresponding Cayley graph of T . Certain Cayley graphs, i.e. star and pancake graphs were shown by Akers and Krishnamurthy [1] to have diameter that is sub-logarithmic in the number of vertices, i.e. n!; e.g. diameter of the pancake graph ≤ 18n/11 [6]. A good comparison between star and pancake networks is given in [25]. Thus, Cayley networks were established as a better topology than hypercubes (that have logarithmic diameter) for interconnection networks. Cayley networks also possess other desirable features like vertex symmetry and small diameter [1]. The details of which can be gleaned from Lakshmivarahan et al. [24], Du and Hsu [13], Heydemann [20], and Xu [31]. For a more details, please refer to [17]. Determining an exact upper bound to sort permutations under various operations, i.e. reversals, transpositions etc. is of much interest. Say, the exact upper bound to sort any π ∈ Pn for an operation Ψ is k, then there exist a pair of permutations πa , πb ∈ Pn such that k moves of Ψ are required to transform πa into πb . In the corresponding Cayley graph Γ , a vertex is identified by the corresponding permutation and an edge (φ, ι) implies that ι can be reached from φ upon application of one generator of Ψ . In other words, dΓ (πa , πb ) = k. So, an exact upper bound to sort any π ∈ Pn equals diam(Γ ). Conversely, an estimate of one is an estimate of the other. Akers and Krishnamurthy provide an upper bound for the diameter of Cayley graphs that are generated by transposition trees in Ω(n!n2 ) time where the factor n2 comes due to the pair wise distance computation [1]. Given a transposition tree T , Ganesan [17] computes β, an estimate of the exact upper bound. β is computed by deleting a pair of terminal vertices per iteration that are diam(T ) apart until a base case is reached. However, in each iteration there can be several pairs that meet the criterion. Thus, the value computed depends on the choice of vertex pairs. In general, given the transposition tree T , the corresponding β need not be unique; i.e. the algorithm is not deterministic. Note that βmax is the maximum possible value of β where each β is computed by a sequence of deletion
Sorting permutations with a transposition tree
3
of vertices. Potentially such sequences are exponential in n. βmax is shown to be an upper bound. Further, it is shown that βmax ≤ f (Γ ). Also, [17] demonstrated a case where β < βmax for a particular sequence of deletion of vertices. In this article, the complexity refers to the time complexity. Similarly, a bound denotes an upper bound and an exact bound denotes an exact upper bound. We compute two upper bounds γ and δ ′ in O(n2 ) time and O(n4 ) time respectively. To compute δ ′ we first compute another upper bound δ in O(n2 ). The parameter δ is designed to yield a unique value for a given tree, i.e. it is deterministic. It is enhanced to yield δ ′ . β, γ and δ ′ are not deterministic. However, any value of ′ γ (resp. δ ′ ), including γmin (resp. δmin ), the least such value for a given tree T is an upper bound. Our implementation results on trees with 6 ≤ |VT | ≤ 10 show that the cumulative values of δ ′ and γ are smaller than that of β.
2
Prior work
The exact upper bound for sorting a permutation with a set of generators is identical to the diameter of the corresponding Cayley graph. For several operations computing the exact bound is NP-complete and for several other operations the corresponding complexity is unknown [15]. Computing tight upper bounds in polynomial time is of continued interest. Even for simple operations i.e. a set of generators, there is scope for improvement. In our case, each member of the set of edges of T , i.e ET constitutes a generator, and its application (say to a permutation π) is a move. Thus, T has n − 1 generators. For a given operation, there are corresponding generators. Consider the operation prefix reversal ; here, given π ∈ Pn , a prefix of length k where 2 ≤ k ≤ n is reversed. Prefix reversal has n − 1 generators corresponding to k = 2 . . . n. Fertin et al. [15] present a good summary of the vast amount of research done in this area. Here, we state a few results for some operations. Recently, computing the exact upper bound for prefix reversals is shown to be NP-complete [2]. In 2009 Chitturi et al. [6] improved the upper bound given by Gates and Papadimitriou [18] for the same problem. The problem of determining the exact upper bound for sorting a cyclic permutation with adjacent transpositions was introduced by Jerrum [22]; for which Feng et al. [14] prove a lower bound of n2 /4 and conjecture that n2 /4 is an upper bound. For prefix transpositions Chitturi and Sudborough [8] prove an upper bound of n − log9/2 n and they conjecture that 3n/4 is an exact upper bound. A string is a sequence in which symbols can repeat. As opposed to a permutation, for a string, the inverse is not well defined. A research area that is related to the current article pertains to transforming one given string into another with a given operation. Only the strings that can be transformed into each other (similar strings) are considered. The complexity of transforming one string into another is NP-complete for several operations [7]. Further, sorting is not the hardest of string transformations; e.g. Hurkens et al. [21] gave an optimal algorithm to sort ternary strings with prefix reversals. However, the corresponding problem of transforming a ternary string into another similar string with prefix
4
Bhadrachalam Chitturi
reversals is NP-complete [4][21]. A degenerate tree (or a bubble sort graph [1]) is a spanning tree in which all vertices except the two terminal vertices have a degree of two. When T is a degenerate tree, Chitturi et al. [5] designed a O(qn) algorithm to determine the exact upper bound for transforming a given string into another similar string where q is the number of symbols. Recall that for a string q < n and typically q = O(1); e.g. for binary strings q = 2. We employ the following terminology from [1] [17] [19]. Let T be transposition (spanning) tree on a vertex set {1, 2, . . . , n} and let π ∈ Pn be a permutation for which we seek dΓ (π, In ) where In = (1, 2, . . . , n), the identity permutation. If π = (6, 5, 4, 3, 2, 1) then π ∈ P6 and in cycle representation π = (1, 6)(2, 5)(3, 4) that is, π has three cycles i.e. η(π) = 3 [1]. Likewise, if π = (5, 4, 3, 2, 1) = (1, 5)(2, 4)(3) then η(π) = 3. Any marker π(i) resides at vertex i. An edge of T between vertex i and vertex j and the corresponding move are denoted by (i, j), (i j) respectively. If (i j) is executed on π then we obtain π(i j), the result of application of (i j) to π. If π(i) = k then VTk or k is home for π(i). Executing a sequence of moves to place π(i) at its home is called homing π(i). The problem of computing dΓ (π, In ) is thus equivalent to that of computing the minimum number of moves required to home all markers. The original result for an upper bound [1] is stated below. For transpositions on permutations, dΓ (ι, θ) = dΓ (θ−1 ι, I). So, Corollary 2 follows [1] [17]. Theorem 1 Let Γ be the Cayley graph generated by a transposition tree T . P Then, for any π in the symmetric group Pn , dΓ (π, In ) ≤ η(π)−n+ ni=1 dT (i, π(i)), where η(π) is the number of cycles (including invariances i.e. fixed points) in the disjoint cycle representation of π. Corollary 2 diam(Γ ) ≤ arg maxπ∈Pn {η(π) − n + right hand side equals f (Γ ).
Pn
i=1
dT (i, π(i))}. Where the
The exact upper bound for sorting any π ∈ Pn with the transposition tree T is identified only for some trees. In general, from the literature, we could only identify bounds such as Corollary 2 and β [17]. In specific instances, when T is K1,n−1 , a star graph, with one central vertex and n − 1 leaves the exact upper bound equals ⌊3(n − 1)/2⌋ [1]. Likewise, the exact bound of bubble sort graph, also known as a Hamiltonian path [19], equals n C2 , the number of inversions in the reverse order permutation: (n, n − 1, . . . 1) [1] [11] [23]. Recently, Ganesan [16] showed that ∀ n > 5 there exists a tree T such that f (Γ ) − diam(Γ ) ≥ n − 4 and also β − diam(Γ ) ≥ n − 4. Note that βmax ≤ f (Γ ) where Corollary 2 gives the value of f (Γ ) [1]. If n < 6, an exhaustive search directly yields an exact upper bound. Thus, in this article n ≥ 6. In Section 3 we compute upper bounds γ (Algorithm G) and δ (Algorithm D ), each in O(n2 ) time. In Section 4 we compute δ ′ (Algorithm D’ ) in O(n2 ) time. In Section 5 we compare our bounds to β [17] and f (Γ ) [1]. In Section 6 we introduce string transformations with transposition trees and state the conclusions.
Sorting permutations with a transposition tree
3
5
Algorithms
Eccentricity of a vertex v ∈ T , i.e. ecc(v) = arg maxi∈T dT (v, i). Intuitively the vertices that are at the periphery have larger eccentricity. A vertex or two vertices connected by an edge of a given tree T with minimum eccentricity constitute the center of T . The center can be computed by repeatedly deleting all the leaves of the tree, until an edge or a vertex remains. If a degenerate tree has an even number of vertices then the center is an edge, otherwise, the center is a vertex. Any path of length diam(T ) passes through the center. Let T be a transposition tree and let π be a permutation. Recall that the marker j = π(i) resides at i. Let the home of marker j be a leaf in T . Observation 1: If a marker j is homed to the corresponding leaf then the permutation can be sorted without moving j again. Proof: Assume that π(i) = j and that the vertex j is a leaf vertex in T for some arbitrary i and j. We home π(i) to vertex j via the simple path from i to j in T . From now on, vertex j does not belong to any simple path between any marker and its destination. Thus, the homed marker at j need not be moved again (in order to home any other marker). Let π 1 be the resultant π where the markers of π are positioned as dictated by the homing of π(i) to vertex j. Here, ∀k π 1 (k) resides at k and vertex j is deleted. One can sort π by homing markers of π 1 in the resultant tree. This argument holds for any subsequent tree. Given T , our greedy algorithms compute the respective upper bounds by deleting the leaves of T . For algorithms, we follow the notation of Cormen et al. and Knuth [11] [23]. Deleting a leaf and the incident edge of a tree yields another tree which is a spanning tree for the remaining vertices. Thus, the algorithms are always manipulating a tree. Algorithm G finds a recluse (defined below) and deletes it. Conceptually we are trying to make the residual tree compact. A simple proof by contradiction shows that, in a tree, recluse is a leaf. That is, if u was a non leaf vertex on a path from the center of the tree to a leaf v then it is easy to show that distSum(v) > distSum(u). Algorithm D and Algorithm D’ seek to identify respective sets of leaves whose deletion will reduce diam(T ) (by at most two). We denote the cardinality of VT by |VT |. Initially, |VT | = n. For a vertex u we define distSum(u) = ∀x∈VT ΣdT (u, x). Bruell et al. [3] call a vertex u as a median of the tree if distSum(u) = arg minx distSum(x). Likewise, we call a vertex u as a recluse of the tree if distSum(u) = arg maxx distSum(x). If the center of T is a vertex say c then if we let c be the root of T then two vertices u and v are on the same branch if their common ancestor is a descendent of the center. If the center of T is an edge (c1 , c2 ) then consider two subtrees, one rooted at c1 and another rooted at c2 where the edge (c1 , c2 ) is assumed to be deleted. Here, u and v are on the same branch if both of them belong to the same subtree. Given a transposition tree T , Algorithm 1 computes a value γ which is an upper bound for sorting any permutation with T . In step G2 we pick the recluse with the minimum index.
6
Bhadrachalam Chitturi
Algorithm 1 Algorithm G 1: 2: 3: 4: 5: 6:
G1: γ ← 0. if T is a star graph then γ ← γ + ⌊3/2(|VT | − 1)⌋ and terminate. end if while VT 6= φ do X dT (i, x) G2: Identify i ∈ VT | arg maxi ∀x
7: G3: γ ← γ + ecc(i); VT ← VT − i; 8: if T is a star graph then γ ← γ + ⌊3/2(|VT | − 1)⌋ and terminate. 9: end if 10: end while
Breadth first search, BFS, on a tree runs in O(n) time. We compute all pairs shortest paths (APSP) in O(n2 ) time by executing BFS from every vertex. ∀ui ∈T we compute distSum(ui ) in n ∗ O(n) = O(n2 ) time. So, this pre-computation is executed in O(n2 ) time. For any u, if distSum(u) = |VT | − 1 then T is a star graph; this can be checked in O(n) time. The following steps are executed at most n − 3 times and each require O(n) time. Thus, the total time complexity of Algorithm 1 is O(n2 ). – Identify if T is a star graph in O(n) time. – Identify a vertex i where distSum(i) = arg maxx distSum(x) in O(n) time. – In the distance matrix, in O(n) time mark the entries of the ith row and the ith column as invalid. – Update γ in O(1) time. – For ∀x ∈ VT − i, decrement distSum(x) by dT (x, i) in O(n) time. Given T , Algorithm 2 computes a value δ which is an upper bound for sorting any permutation with T . Note that step D2 identifies a unique set. When a set of vertices are deleted from T then we assume that the vertex identities of residual T are (1, 2 . . . |VT1 |) where T1 is the residual tree. The following simple algorithm, Algorithm S, identifies the set of all vertices that have maximum eccentricity i.e. S (computed in step D2 of Algorithm 2) in T in linear time. Algorithm S – a) Execute BFS from an arbitrary leaf u and identify a vertex i that is farthest from u. – b) From vertex i execute another BFS to identify X ⊂ VT where X has all vertices that are farthest from i. – c) Execute another BFS from x ∈ X and identify the vertices that are farthest from x, yielding set Y ⊂ VT . The vertices in T with maximum eccentricity are given by the set S = i ∪ X ∪ Y . In Step a) the simple path from i to u will pass through the center of T . Furthermore, i will be a vertex with maximum eccentricity [26]. That is, if the
Sorting permutations with a transposition tree
7
center of T is a vertex, say c, then dT (c, i) = diam(T )/2. In Step b) for any x ∈ X, dT (x, i) = diam(T ) and dT (x, c) = diam(T /2). If the center of T is a vertex then S = X ∪ i and we can terminate after Step b). However, if the center is an edge then the set X will belong to one branch only. Thus, we need to execute Step c) also. Note that, if the first vertex u ∈ S then we can save the last BFS in both cases, i.e. when the center is a vertex or an edge. However, we do not know if an arbitrary leaf u ∈ S. Note that, one can easily determine if u is a leaf in O(n) time. BFS on a tree can be computed in linear time, so, S can be found in O(n) time. Algorithm 2 Algorithm D 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
D1: δ ← 0. if T is a star graph then δ ← δ + ⌊3/2(|VT | − 1)⌋ and terminate. end if while VT 6= φ do D2: Execute Algorithm S on T and identify S D3: if |S| is even then δ ← δ + |S| ∗ (diam(T ) − 1/2); VT ← VT \ S; else δ ← δ + |S| ∗ (diam(T ) − 1/2) − 1/2; VT ← VT \ S; end if if T is a star graph then δ ← δ + ⌊3/2(|VT | − 1)⌋ and terminate. end if end while
The following steps are executed until a base case is reached. – 1) If T is a star graph then update δ and terminate (O(n) time). – 2) Compute S in O(n) time. Update δ in O(1) time. – 3) Delete all the vertices of S, say k of them, in O(kn) time. Go to Step 1). Overall, Step 1) can be executed in O(n2 ) time because at most n/2 iterations each deleting at least two vertices are executed. Step 2) is bounded above by n/2 ∗ O(n) = O(n2 ) time. At most n − 3 vertices are deleted before a star graph is formed and each vertex deletion requires O(n) time yielding an overall complexity of O(n2 ) time for Step 3). Thus, Algorithm 2 runs in O(n2 ) time. 3.1
Properties of Bounds
Consider two isomorphic trees T 1 and T 2 whose corresponding labels are given by the permutations L1 = (1, 2, , . . . n) and L2 = (l1 , l2 , l3 , . . . ln ) where the correspondence for the labels is given by (i, li ). Also, let Γ 1, Γ 2 be the respective Cayley graphs. Heydemann et al. state that if T 1 and T 2 are isomorphic then their corresponding Cayley graphs are also isomorphic [19]. It follows
8
Bhadrachalam Chitturi
that diam(Γ 1) = diam(Γ 2). The following is our argument for the same. Let σ be the permutation (operation) that maps L1 to L2. For T 1, let π1 ∈ Pn be such that distΓ 1 (π1 , In ) = diam(Γ 1) then π1 σ is a permutation such that distΓ 2 (π1 σ, In ) = diam(Γ 1). Conversely, let π2 be a permutation in Γ 2 such that distΓ 2 (π2 , In ) > distΓ 1 (π1 , In ). It follows that π2 σ −1 requires the same number of moves (> diam(Γ 1)) to be sorted in Γ 1, which is a contradiction. Thus, diam(Γ 1) = diam(Γ 2). Theorem 3 γ is an upper bound for sorting permutations in Pn with a given transposition tree T where |VT | = n. Proof. A vertex u that is deleted in a given iteration is the destination of the corresponding marker. For a given u ∈ T , the corresponding homing can be executed in at most ecc(u) moves. The process is repeated for the resultant tree. This is an implicit algorithm to sort any permutation with T . Thus, γ is an upper bound. Lemma 4 For any tree T , there exist two leaves u, v such that the markers destined to u and v can both be homed in at most 2 ∗ diam(T ) − 1 moves. Proof. If there is a marker in T that can be homed in at most diam(T )−1 moves then clearly 2 ∗ diam(T ) − 1 moves are sufficient to home two markers to two leaves because the second marker can always be homed in diam(T ) moves. Thus, the case left to consider is: every marker resides at a leaf and is diam(T ) away from its respective home which is also a leaf. This scenario yields the following cases: Case 1: there are two leaves u, v that are diam(T ) apart such that marker at u is destined to v and vice versa and Case 2: no such pair of leaves exist. In Case 1 one can arbitrarily home one marker first. This sequence of diam(T ) moves brings the second marker one closer to the destination. Thus, the second marker can be homed in diam(T ) − 1 moves. So, 2 ∗ diam(T ) − 1 moves are sufficient. In Case 2 every leaf li is the home for the corresponding marker π(lj ) where π(lj ) is the marker at the leaf lj where i 6= j and dT (i, j) = diam(T ). Imagine drawing a directed edge from la to lb if π(la ) is destined to lb . If we have la → lb and lb → la then we arrive at Case 1. So, we ignore this case. Thus, there is a directed path of the form la → lb → lc . In this case, we first home π(la ) to lb , this sequence of diam(T ) moves will position π(lb ) one edge closer to lc . So, π(lb ) can be homed in diam(T ) − 1 moves. Thus, 2 ∗ diam(T ) − 1 moves are sufficient. Lemma 4 explains the rationale for β [17] (please see Section 1). However, the exact pair of vertices that must be deleted in the worst case might be different from the vertices deleted by the algorithm that computes β. Hence, β is not guaranteed to be an upper bound. Let π be a permutation that is being sorted by a given T . Let ∀i li be a set of leaves of T . Assume that all the markers whose corresponding homes are li ∀i are homed. Then by a simple extension of Observation 1 (given earlier in Section
Sorting permutations with a transposition tree
9
3), in order to sort π, no further moves involving any li are needed. We want to establish an upper bound on the number of moves required to home all the markers destined to li ∀i where ∀i ∃vi ∈ T | dT (li , vi ) = diam(T ). To this end, we extend Lemma 4 and prove a more general result. The proof is similar. Lemma 5 Let S ⊂ V be a set of leaves such ∀ u ∈ S ∃v ∈ V | dT (u, v) = diam(T ). Then all the markers that must be homed to the vertices of S can be homed in at most |S|(diam(T ) − 1/2) moves where diam(T ) > 2. Proof. Let S = l1 , l2 , . . . , l|S| . A total of |S| markers need to be homed yielding (diam(T ) − 1/2) moves per homing of a marker. If a marker destined to li can be homed in at most diam(T ) − 1 moves then for S − li we need to prove a weaker result. Thus, the worst case occurs when every marker is diam(T ) away from its respective home. It follows that a marker destined to a leaf in S resides at another leaf that also belongs to S, i.e. any marker π(li ) at li is destined to lj for some j and dT (li , lj ) = diam(T ). Imagine drawing a directed edge from la to lb if π(la ) is destined to lb . Such a diagram clearly has at least one directed cycle. If la and lb have a directed cycle between them then their markers can be homed in 2diam(T ) − 1 moves which respects our bound (see Lemma 4). Consider three leaves lu , lv , lw that have a cycle of length three; i.e. lu → lv → lw → lu . Consider homing the corresponding markers π(lu ), π(lv ), π(lw ) in the order dictated by this cycle. Say, move π(lu ) to lv then move π(lv ) to lw and finally move π(lw ) to lu . The first homing needs diam(T ) moves and any of the subsequent homing needs diam(T ) − 1 moves. Note that the first marker to be homed can be chosen arbitrarily as long as the sequence dictated by the cycle is followed. Moreover, this is extensible for a cycle of any length where a cycle of length p needs p(diam(T ) − 1) + 1 moves. The total number of moves to home all markers is maximized when the length of the cycle is minimized, i.e. the length is two. Thus, if the parity of |S| is even then the worst case is |S|/2 cycles of length two. This corresponds to a total of |S|/2(2diam(T ) − 1) = |S|(diam(T ) − 1/2) moves. However, when the parity of |S| is odd then the worst case corresponds to maximizing the number of cycles of length two, that is we have (|S| − 3)/2 cycles of length two and one cycle of length three. This corresponds to a total of |S|(diam(T ) − 1/2) − 1/2 moves. So, |S|(diam(T ) − 1/2) moves suffice. Theorem 6 δ is an upper bound for sorting permutations in Pn with a given transposition tree T where |VT | = n. Proof. Let S be the set of all leaves that are at a distance diam(T ) from some other leaf in T . Lemma 5 shows that in the worst case all such leaves can be can be homed in |S|(diam(T ) − 1/2) or |S|(diam(T ) − 1/2) − 1/2 moves depending on whether the parity of |S| is even or odd. Algorithm D computes this value for the tree T . Thus, it is an upper bound.
10
4
Bhadrachalam Chitturi
Refinements
Lemma 5 computes an upper bound for the worst case. Thus, it holds for a set S even when every pair of leaves within S is diam(T ) apart. However, consider a scenario where if a vertex u in S were to be deleted then the diameter of T reduces (by one). If the vertex u were to be homed followed by homing members of S − u then in the worst case diam(T ) + |S − 1|(diam(T ) − 3/2) moves (the second term is due to Lemma 5 applied to |S − 1| vertices) are required in contrast to the bound of |S|(diam(T ) − 1/2) given by Lemma 5 when all the vertices are considered together. The advantage of homing u first is minimized when |S| is odd; in such a case the number of moves one saves is given by |S|(diam(T ) − 1/2) − 1/2 − (|S − 1|(diam(T ) − 3/2) + diam(T )) which equals |S| − 2. Clearly homing u first is more efficient when |S| > 2. Likewise, one needs a general criterion which determines whether homing a few vertices of S individually (where each incurs a maximum cost of diam(T ) moves) is more efficient than the bound dictated by Lemma 5 (for all the vertices together). Consider the scenario where deleting x leaves that are members of S reduces diam(T ) by one. We have to make a greedy choice between the following two cases: Case (a) deleting these x leaves at the cost of x diam(T ) and Case (b) deleting the entire set S at the cost of at most S(diam(T ) − 1/2). The projected cost of deleting the remaining |S|−x leaves in Case (a) equals (|S|−x)(diam(T )− 3/2). Thus, we will prefer Case (a) if x diam(T ) + (|S| − x)(diam(T ) − 3/2) ≤ S(diam(T ) − 1/2) which yields x ≤ 2|S|/3. Clearly, the lowest value of x is sought. We seek to identify a subset S1 of S with minimum cardinality such that its deletion will reduce diam(T ). To this end, we design a clustering algorithm, Algorithm NC, which accepts S as the input. The clustering is based on how far apart a pair of vertices are allowed to be from one another within the cluster. We call this distance bound as limit. Subsequently we give an algorithm Algorithm D’ that will compute an upper bound δ ′ . It is based on Algorithm NC. Let u, v ∈ S | dT (u, v) < diam(T ). Let us assume that u and v are on different branches and say that center of T is a vertex. Without loss of generality, assume that t is a vertex that is diam(T ) away from u. Thus, dT (c, t) > dT (c, v). Likewise, assume that s is a vertex that is diam(T ) away from v. Thus, dT (c, s) > dT (c, u). The distance from t to s equals dT (t, c)+dT (c, s) > dT (t, c)+dT (c, u) = diam(T ), which is a contradiction. Thus, u and v are on the same branch. Similarly it can be demonstrated that u and v are on the same branch even when the center is an edge. It follows that if u and v are on different branches then dT (u, v) = diam(T ). Lemma 7 For any two vertices u, v ∈ S, if dT (u, v) < diam(T ) then (i) dT (u, v) is even and (ii) u, v are equidistant from their common ancestor if the center of the tree were the root. Proof. Recall that S is the set of all vertices that are diam(T ) from some vertex in the transposition tree T . By definition, if dT (u, v) = diam(T ) then u ∈ S ∧v ∈
Sorting permutations with a transposition tree
11
S. If the center of T is a vertex then we denote it by c, otherwise, center is an edge and c denotes the vertex of the center that is closer to u and v. Note that if u and v are on the different sides of the center then dT (u, v) = diam(T ), a contradiction. First, we note that for any u, v ∈ S, if dT (u, v) = 1 then one of them cannot be a leaf, which is a contradiction. Let dT (u, v) = x < diam(T ) and if c were the root then let w be the common ancestor of u, v. In this scenario, path from u to a vertex t that is diam(T ) away passes through w. If dT (u, w) 6= dT (v, w) then without loss of generality let dT (u, w) < dT (v, w). Note that ∃t ∈ S | dT (u, t) = diam(T ). Note that t belongs to another branch and a path from v to t passes through c, consequently, it must pass through w. In such a case dT (v, t) ≥ diam(T ) + 1 which is a contradiction. A similar argument shows that dT (u, w) = dT (v, w) even when the center of the graph is an edge. Thus, dT (u, v) = 2 ∗ dT (u, w) = 2 ∗ dT (v, w) is even. Lemma 8 Let {u, v, w} ∈ S where dT (u, v) < dT (u, w) < diam(T ) then dT (u, w) = dT (v, w). Proof. Clearly, u, v, w are on the same branch. Further, let x be the common ancestor of u, v and let y be the common ancestor of x, w. Then dT (u, w) = dT (u, y) + dT (y, w) = dT (u, x) + dT (x, y) + dT (y, w) = dT (v, x) + dT (x, y) + dT (y, w). Recall that dT (u, x) = dT (v, x). Thus, dT (u, w) = dT (v, w). The design of Algorithm NC is based on Lemmas 7 and 8. Given a transposition tree T , and S, this algorithm computes clusters starting from singletons of S. Recall that some pairs of vertices in S can be < diam(T ) apart. We define limit as the maximum distance between any pair of vertices in a given cluster. That is, the limit equals zero in the first iteration and it is incremented by two after every iteration (Lemma 7). In the last iteration it equals diam(T ) − 1 or diam(T ) − 2, i.e. the maximum limit based on whether diam(T ) is odd or even. All the vertices that are within limit of each other are placed in a cluster. We define a singleton to be a cluster with one vertex. We denote the set of clusters formed at limit = x by Cx . CxΣ comprises of all clusters where the limit of any cluster is at most x. For a given vertex v, distSum(v) = Σi dT (v, ui ) where ui ∈ T . For a given cluster C, distSum(C) = Σui ∈C distSum(ui ). Let ∗ ∗ Cmax be the set of all clusters with limit ≤ maximum limit. Let Cp , Cq ∈ Cmax be two arbitrary clusters. Here, vertex pairs within Cp are < diam(T ) apart and d(u, v) = diam(T ) if u ∈ Cp , v ∈ Cq . If vertices of S\Cp are deleted then diam(T ) reduces. Further, if any w ∈ S \ Cp is not deleted then ∀u ∈ Cp , d(u, w) = diam(T ). Thus, ∀p {S \ Cp } constitutes the set of optimum solutions O∗ where |Cp | = argmaxi |Ci |. One can cluster the vertices of S using only the maximum value of the limit. However, the hierarchical structure provided by our algorithm can be used for various heuristics. For example, we can find S \ Cp ∈ O∗ such that the value of limit needed to cluster all the members of Cp is the minimum. Clusters Ca , Cb can be merged if the distance between any u ∈ Ca and any v ∈ Cb equals limit. Per Lemma 8, only one comparison suffices instead of
12
Bhadrachalam Chitturi
Algorithm 3 Algorithm NC 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
NC1. C0 ← v1 , v2 , . . . , v|S| where ∀i vi ∈ S; mergeCount ← 0; for (k = 1 to (diam(T ) + 1)/2 − 1) do Σ C2k ← φ, C2k ←φ end for NC2. for (k = 1 to (diam(T ) + 1)/2 − 1) do Σ Σ C2k ← C2k−2 Σ Σ for (each pair (Ca , Cb ) | (Ca ∈ C2k ∧ Cb ∈ C2k ) ∧ a 6= b) do if dT (u, v) = 2k f or any (u ∈ Ca ∧ v ∈ Cb ) then Cab ← merge (Ca , Cb ); //Only one pair Cai , Cbj is checked Σ Σ C2k ← C2k ∪ Cab //Merge removes Ca , Cb C2k ← C2k ∪ Cab − Ca − Cb mergeCount ← mergeCount + 1; end if // Number of clusters = |S| − mergeCount end for end for
|Ca ||Cb | comparisons. Initially, when all clusters are singletons, n C2 comparisons are necessary to check all pairs. However, if the number of clusters decrease to m(< n) then corresponding number of comparisons decreases to m C2 . The iterations are bounded by O(n). Thus, the time complexity of Algorithm NC is O(n3 ). Note that originally every cluster is a singleton, each containing one member of S. At the termination of the algorithm every cluster is a subset of S; i.e. all the singletons cannot be merged into a single cluster (= S) because limit < diam(T ). For a given limit l, assume that Ca and Cb cannot be merged and that Ca and Cc can be merged into Cac then Cac cannot be merged with Cb for the limit l (see Lemma 8). This property simplifies our computation. Given a transposition tree T , Algorithm D’ computes the corresponding δ ′ . It is based on Algorithm NC. O(n) iterations that execute Algorithm NC determine the time complexity of the algorithm, i.e. O(n4 ). Note that one can arbitrarily choose between two candidate clusters of the same size and the same distSum. Thus, in contrast to δ, δ ′ is not unique. The following algorithm, Algorithm F ast N C improves the running time of Algorithm NC to O(n) yielding O(n2 ) time for computing δ ′ . It is based on the following facts: (i) let r(T )(= root(T )) = center(T ) = c; let aij be the lowest common ancestor of li , lj ∈ S; if aij 6= c then li , lj ∈ the same cluster (pairwise distance comparisons are avoided) and (ii) two linked lists can be concatenated in O(1) time. The output is a tree TS ⊆ T with li ∈ S as leaves and r(TS ) = c. Also, TS contains all the hierarchical information of the clusters. The critical case for Algorithm D’ corr. |C| = 2S/3. Here, we give an alter′ nate option that leads to the computation of a variation of δ ′ i.e. δv2 . Algorithm Fast NC
Sorting permutations with a transposition tree
13
•Identify the center c of T in O(n) time. If c = (u, v) (an edge) then reduce c into a vertex: ∀x and ∀y replace O(n) edges (u, x), (v, y) resp. with (c, x), (c, y) (now c ∈ VT ). This deems diam(T ) of the resulting tree even. Note that we need only identify O∗ . The exact value of the diameter is maintained in Algorithm D’. • In O(n) time perform BFS from c thereby rendering c as the root of T and for all distances ≤ diam(T )/2 identifying all the vertices (and their corr. pointers) at a given distance from c. Let the children of c be C = cl1 , cl2 , . . . cli . Let predecessor(u) be the predecessor of u. •Initialize in O(n) time: Mark all li ∈ S. Let Rec ids(x) be the linked list of received vertex ids. at x. ∀x if x ∈ S then Rec ids(x) = x, otherwise Rec ids(x) = φ. • Process T bottom up visiting all vertices that are x apart from c where x = (diam(T )/2, diam(T )/2 − 1, . . . , 1) as indicated below in O(n) time. For each marked vertex u: (i) if u ∈ S, Rec ids(u) = u else Rec ids(u)= concatenation (∀i Rec ids(ui )) where ∀i ui is a child of u. Send Rec ids(u) to predecessor(u), (ii) create a special pointer from predecessor(u) to u, and (iii) mark predecessor(u). • At c: if Rec ids(clk ) = argmaxj (Rec ids(clj )) then S \ Rec ids(clk ) ∈ O∗ . Theorem 9 δ ′ is an upper bound for sorting permutations in Pn with a given transposition tree T where |VT | = n. Proof. We have two cases depending upon whether a subset of S, i.e. a cluster, at most 2|S|/3 in size exists such that its deletion reduces diam(T ) (Case 1) or does not exist (Case 2). In Case 2, the markers are homed as dictated by Lemma 5. In Case 1 each marker of the cluster is homed individually and diam(T ) moves that are allowed per marker are sufficient. Thus, we have a straight forward algorithm that respects δ ′ .
5
Results
In this section we theoretically compare our bounds with β for a class of trees and state our implementation results for all trees. In [17] it was shown that βmax ≤ f (Γ ) (β ≤ βmax ); thus, it suffices to compare our bounds with β. For a bubble sort graph, we note that β, γ and δ ′ compute the value that equals the exact upper bound. In order to corroborate our implementation results, we compute β, γ and δ ′ on a complete binary tree. For these algorithms, even though at several stages of execution there is a choice between selecting either the right or the left subtree, the values computed are identical and the resultant trees from either choice are isomorphic. Thus, the trace on a complete binary tree is instructive. Let B d be a complete binary tree with depth d and let m be the number of its leaves i.e. m = 2d and total number of vertices equals n = 2m − 1. Let BLd d d d and BR be its left and right subtrees. Likewise, let Let BRL and BRR be the left
14
Bhadrachalam Chitturi
Algorithm 4 Algorithm D’ 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
D1’. δ′ ← 0 if T is a star graph then δ ′ ← δ ′ + ⌊3/2(|VT | − 1)⌋ and terminate. end if D2’. Run Algorithm S and identify S. D3’. Execute Algorithm NC and compute clusters for S. D4’. ∗ Identify C = S − C ∗ where C ∗ ∈ Cmax and |C ∗ | is the max. and distSum(C ∗ ) is the min. (break ties arbitrarily), VC : nodes of C ( diam(T \ VC ) < diam(T )). ′ Case 1: |C| > 2|S|/3 //|C| ≥ 2|S|/3 computes δv2 if |S| is even then δ ′ ← δ ′ + |S| ∗ (diam(T ) − 1/2); T ← T \ S else δ ′ ← δ ′ + |S| ∗ (diam(T ) − 1/2) − 1/2; T ← T \ S end if End Case 1 ′ Case 2: |C| ≤ 2|S|/3 //|C| < 2|S|/3 computes δv2 δ ′ ← δ ′ + |C| ∗ diam(T ); T ← T \ VC End Case 2 if T is not a star graph then go to step D2’. else δ ′ ← δ ′ + ⌊3/2(|VT | − 1)⌋ and terminate. end if
d and the right subtrees of BR respectively. Let r(B d ) be the root of B d and let d l(B ) indicate all the leaves of B d . Note that as the tree is manipulated, l(B d ) changes.
5.1
Comparison of the upper bounds with a complete binary tree
We call the algorithm that computes β (resp. δ ′ , γ) as Aβ (resp. Aδ′ , Aγ ). A leaf at a distance x from the root is said to be at depth x. First, we trace Aβ on d B d . In the first iteration, Aβ chooses a pair of leaves, one each from BLd and BR , deletes them and increments the value of β to 4d − 1 where 2d is the diameter of B d . This process is repeated for m/2 iterations until all m leaves at depth d are deleted, two leaves per iteration. The current X value of β equals m/2(4d − 1) and d−1 the resultant tree is B . Thus, β − 3 = m/2k (2(2d − 2(k − 1)) − 1) k=1...d−1
where three is the value of β(B 1 ). R.H.S Xof the above equation can be written as X − Y where X = (m/2)(4d − 1) 1/2k and Y = m(1 + 2/2 + 3/22 + k=0...d−2
. . . (d − 2)/2d−3). X simplifies to 4md − 8d − m + 2 and Y simplifies to 4m − 8d.
Sorting permutations with a transposition tree
15
Thus, β = 4md − 5m + 5. For m = 8, 16 corresponding to d = 3, 4 this formula yields 61 and 181 respectively. Recall that Aδ′ deletes up to 2|S|/3 vertices each at a cost of diam(T ) if the diameter of the resultant tree is reduced. Aδ′ begins by deleting all the leaves of d d BR (WLOG we choose the right subtree i.e. we start by deleting l(BR )) and δ ′ d d is assigned m/2 ∗ 2d = md. Note that |l(BR )| = |l(B )|/2 where currently S = l(B d ). After this iteration diam(B d ) decreases by one. In the next iteration, Aδ′ d deletes all the leaves of the subsequent BR and increments δ ′ by m/4 ∗ (2d − 1) = ′ md/2 − m/4. Thus, δ = 3md/2 − m/4 and diam(B d ) = 2d − 2. These moves d and constitute phase 1 of Aδ′ . Currently, the distance between leaves of the BLL d d d d BLR i.e. 2d − 2 equals diam(T ). Thus, S = l(BLL ) ∪ l(BLR ) ∪ l(BR ), the union of leaves of three different subtrees. Any u, v ∈ S each belonging to a different subtree are 2d − 2 i.e. diam(T ) apart. The next two iterations constitute Phase 2. Table 1 shows the various phases, the iterations within a phase, the cost per deletion of a leaf in a given iteration of a given phase and the number of leaves of a subtree that are being deleted at the specified cost. In a given iteration, all the leaves of the specified subtree, say Ts are deleted and their count is given. In the next iteration the number of leaves of Ts that are deleted gets halved and this process culminates in deletion of the root of Ts . The rightmost non-zero entry in each row shows the number of leaves that are deleted from the latest subtree i.e. BLd k R . The corresponding leaves of BLd k L the other subtree of BLd k are not X deleted. Thus, m/2k leaves are not deleted and at most m/2k + m/2k+i i=1...d−k
leaves are deleted. The number of the deleted leaves is at most 2m/2k when r(BLd k ), k > 0 is deleted, 2m/2k − 1 otherwise; in either case it is at most 2|S|/3. d Note that, in Tables 1 and 2 we omit (r(B d ), r(BLd ),r(BLL ) . . . ) with respective 2 costs (d, d − 1, . . .) i.e. a total cost of O(d ). This cost is accounted for by the O(d2 ) term in the final equation. Recall that d = log2 (m).
Table 1. Phases, iterations, cost per vertex deletion, the corresponding subtrees and the count of their leaves in Aδ′ . Here, d is even. d d d d Phase Iteration Cost BR BLR BLLR BLLLR 1 1 2d m/2 0 0 0 1 2 2d-1 m/4 0 0 0 2 3 2d-2 m/8 m/4 0 0 2 4 2d-3 m/16 m/8 0 0 3 5 2d-4 m/32 m/16 m/8 0 3 6 2d-5 m/64 m/32 m/16 0 ... ... ... ... ... ... ... d/2 d d+1 1 2 4 8 d/2+1 d+1 d 0 1 2 4 d/2+1 d+2 d-1 0 0 1 2
...
...
...
...
...
...
...
... 0 0 0 0 0 0 ... ... ... ... ...
16
Bhadrachalam Chitturi
The total contribution of all the subtrees to δ ′ is given by: m/2(2d + (2d − 1)/2 + (2d − 2)/4 + . . . (2d − (d − 1))/2d−1 )+ m/4(2d − 2 + (2d − 3)/2 + (2d − 4)/4 + . . . (2d − d)/2d−2 )+ ... m/2k (2d − 2(k − 1) + (2d − 2(k − 1) − 1)/2 + (2d − 2(k − 1) − 2)/4 + . . . (d − k + 2)/2d−k ))+ ... The (upper triangular) matrix shown in Table 2 gives the terms whose sum equals δ ′ /m. Let Rx indicate the xth row and let Sum(Rx) be the sum of the elements in Rx. Table 2. Matrix representing the terms that add up to δ ′ /m
2d/2 (2d − 1)/22 (2d − 2)/23 (2d − 3)/24 . . . (2d − (d − 1))/2d 0 (2d − 2)/22 (2d − 3)/23 (2d − 4)/24 . . . (2d − d)/2d 3 4 0 0 (2d − 4)/2 (2d − 5)/2 . . . (2d − (d + 1))/2d ... ... ... ... ... ... 0 0 0 0 ... 2/2d
Sum(R1) = 2d(1/2 + 1/22 + 1/23 + 1/24 + . . . + 1/2d) − 1/22 (1 + 2/2 + 3/22 + 4/23 + . . . + (d − 1)/2d−2 ) = 2d(1 − 1/2m) − (1 − (2d + 1)/m) = 2d − 1 + (1 + d)/m. Recall that 2d = m. The summation (1 + 2/2 + 3/22 + 4/23 + . . . + (d − 1)/2d−2 ) is of the form Σ(k)/2k−1 . If we let s = Σ(k)/2k−1 then s − s/2 yields a simple geometric progression (and an additional term) whose evaluation is straightforward. Sum(R1) − Sum(R2) = 2d/2 + 1/22 + 1/23 + . . . + 1/2d = d + 1/2((1 − 2/m) = d + 1/2 − 1/m. Thus, Sum(R2) = d − 3/2 + (2 + d)/m. Likewise, Sum(R3) = d/2−5/4+(3+d)/m, Sum(R4) = d/4−7/8+(4+d)/m, and Sum(R5) = d/8 − 9/16 + (5 + d)/m. The coefficient of d in the entire summation equals 2 + 1 + 1/2 + 1/4 + ....2/2d = 4(1 − 1/2d+1 ) = 4 − 2/m. The constant terms add up to −(1+3/2+5/4+7/8+9/16+. . .) = −(Σ(2k +1)/2k = −(6 − (4 + 8d)/m); note that this summation can be evaluated similar to the summation: Σ(k)/2k−1 . The other terms are divided by m, and they contribute O(d2 )/m to the summation. One must multiply these terms with m to obtain the final value of δ ′ . Thus, δ ′ = m(d(4 − 2/m) − 6 + (4 + 8d)/m + O(d2 )/m) ≈ 4md − 6m + O(d2 ). We call the algorithm that computes γ as Aγ . Let us trace Aγ on B d . Recall that Aγ chooses a recluse say u (i.e. a leaf with the maximum value for distSum) then Aγ deletes u and increments γ by ecc(u). In the first iteration, Aγ chooses d a recluse, (say, WLOG the recluse ∈ l(BR )) deletes it and increments the value d of γ to 2d where 2d is the diameter of B d . Note that initially any leaf of BR qualifies to be a recluse. However, once the recluse is deleted, the distSum of d any leaf of l(BR ) decreases by at most 2d− 2 whereas the same for any leaf of BLd
Sorting permutations with a transposition tree
17
d decreases by 2d. Thus, the subsequent recluses chosen by Aγ belong to l(BR ). For a given B d the leaves at a certain depth h from r(B d ) are said to reside at d level h. We note that after deleting k levels of leaves from BR , distSum of any d x ∈ l(BLd ) decreases by a greater amount than the same of any y ∈ l(BR ). Thus, d the distSum(y) of any y ∈ l(BR ) continues to be greater than distSum(x) d of any x ∈ l(BLd ). So, in sequence, all the leaves of BR are deleted starting d from level d culminating in the deletion of r(BR ) (at level 1). At this juncture r(B d ) is the lone recluse and it is also deleted. The total cost incurred being (m/2(2d) + m/4(2d − 1) + m/8(2d − 2) + . . . + m/2d−1+1 (2d − (d − 1))) + d. Thus, the value of γ for the whole tree is given by the recurrence γ(m, d) = (md + m/4(2d − 1) + m/8(2d − 2) + . . . + d + 1) + d + γ(m/2, d − 1) where the base conditions are given by γ(4, 2) = 15, γ(2, 1) = 3. The recurrence yields γ(m, d) = 4md − 6m + O(d2 ), recall that d = log m, m = (n + 1)/2. Thus, Theorem 10 stated below follows. β(T ) denotes the value of β for the tree T etc..
Theorem 10 For all values of n where n = 2p − 1, p > 3, there exists a tree T with n vertices such that β(T ) − δ ′ (T ) = Ω(n) and β(T ) − γ(T ) = Ω(n). We propose a new parameter λ where λ = min(δ ′ , γ). λ is an upper bound because δ ′ and γ are upper bounds. Thus, from Theorem 10 for a complete binary tree, β(T ) − λ(T ) = Ω(n). The values of δ ′ and β for complete binary trees are (15, 55,156) and (17, 61, 181) respectively for d = 2, 3 and 4. Theorem 10 shows that for a particular tree i.e. a complete binary tree with n = 2p − 1 vertices where p > 3, δ ′ and γ are tighter than β by Ω(n). Here, we introduce a class of trees and prove a stronger result. Similar to the complete binary tree, for this new class of trees, all algorithms behave deterministically (even though at certain stages of execution some of these algorithms can choose between several moves). That is, they compute a unique value for a given T of this class. 5.2
Comparison of the upper bounds with brooms
Consider the tree T = ((1, 2), (2, 3), (3, 4) . . . (n − k − 1, n − k), (n − k, n − k + 1), (n − k, n − k + 2), . . . (n − k, n)). We call T a broom or specifically a k-broom where k > 1. Here, diam(T ) = n − k. Vertex 1 is the handle and the k vertices n − k + 1, . . . n are the spokes. If n ≥ 2k + 1 then we obtain a long broom or specifically a long k-broom. A long broom is balanced if k = Ω(n); we denote its β − γ by ∆n,k and δ ′ equals γ. Consider the tree T1 = {(1, p + 1), (2, p + 1), . . . (p, p + 1), (p + 1, p + 2), (p + 2, p+ 3) . . . (n− k − 1, n− k), (n− k, n− k + 1), (n− k, n− k + 2), . . . (n− k, n)}. We call T1 a double broom where k > 1 and p > 1. Here, diam(T1 ) = n − k − p + 1. Vertices (1, 2, . . . , p) are the left-spokes, (n − k + 1, . . . , n) are the right-spokes and (p + 1, . . . , n − k) are stick-nodes. We say that a double broom is balanced if p = Ω(n) ∧ k = Ω(n) ∧ n > 2k + p + 1 where WLOG we assume that k ≥ p. For a balanced double broom, we denote β − γ by ∆n,p,k where = γ = δ ′ .
18
Bhadrachalam Chitturi
Theorem 11 For all n ≥ 6 there exist Ω(n) trees where β − δ ′ = Ω(n2 ) and β − γ = Ω(n2 ). Proof. Recall that the computation of β proceeds by deleting a pair of vertices that are diam(T ) apart. The computation of β for a balanced long broom proceeds by deleting an arbitrary spoke and the corresponding handle, this process is repeated until all but one spoke is left. At this point T transforms to a bubble sort graph. The value of β for a balanced long broom is given by A+B where A = (2(n− k)−1)+(2(n−k −1)−1)+. . .+(2(n+1−2k)−1) and B = bubble(n−(2k −2)) = n−2k+2 where bubble(x) is the value of β for a bubble sort graph with x vertices. 2 Thus, A = (k−1)/2 (2(2(n−k)−1+(k−2)(−2)) and B = (n−2k+2)(n−2k+1)/2 and β = (n2 − 2k 2 − n + 2k)/2. The handle is the lone recluse that Algorithm G seeks to identify. Likewise, the handle constitutes the cluster that Algorithm D’ seeks to identify which has the least cardinality and whose deletion reduces diam(T ). The values of γ and δ ′ for a long k-broom are identical. Their computation proceeds by successively deleting the handle until T transforms into a K1,k+1 . For K1,x , recall that both Algorithm G and Algorithm D’ increment γ and δ ′ respectively by ⌊3x/2⌋. The value of γ (resp. δ ′ ) for a long k-broom is given by C + D where C = (n−k)+(n−k −1)+. . .+3 and D = 3/2(k +1). Note that, to be precise, we need to take the floor of R.H.S. for evaluating D. However, if we take the floor of the resultant δ ′ our computation will be exact. Thus, γ = δ ′ = (n − k)(n − k + 1)/2 − 2 − 1 + 3(k + 1)/2. Simplifying, γ = δ ′ = (n2 − 2nk + k 2 + n + 2k − 3)/2. Thus, ∆n,k = (2nk − 3k 2 − 2n + 3)/2. To be precise, we need to take the ceiling of the R.H.S.. When k is O(1), clearly ∆n,k = O(n). Note that n ≥ 2k + 1. If we equate the differential of ∆n,k with respect to k to zero then we obtain k = n/3. The second differential is negative, so, when k = n/3, ∆n,k achieves the maximum value of (n − 3)2 /6. Thus, for all n ≥ 6 ∆n,k is Ω(n2 ). In the limiting case that distinguishes a broom from a long broom, i.e. when n = 2k+1, ∆n,k = (n−3)2 /8. Clearly, when k is Ω(n) i.e. for a balanced long broom, ∆n,k = Ω(n2 ). There are Ω(n) such trees. A feasible set of values of k where k = Ω(n) range from (n − 1)/p . . . (n − 1)/2. These values total (n − 1)(p − 2)/(2p) + 1 = Ω(n) for some integer p > 2. Thus, there exist Ω(n) trees (k brooms) for any n where ∆n,k = Ω(n2 ). For example, when n = 10 if we choose p = 4 we have three choices for k i.e. (2,3,4). If k = 2 then ∆10,2 = 43 − 37 = 6, and if k = 3 then ∆10,3 = 39 − 31 = 8, and if k = 4 then ∆10,4 = 33 − 25 = 8. For larger values of n where k = n/3 we note that ∆15,5 = 24, and ∆30,10 = 122. These values show a growth that is clearly quadratic in n. Theorem 6 in [17] proves that βmax ≤ f (Γ ). So, the unique value of β that we computed here is βmax (≤ f (Γ )). Thus, f (Γ ) − δ ′ = Ω(n2 ) and f (Γ ) − γ = Ω(n2 ). Further, it follows that f (Γ ) − λ = Ω(n2 ). Theorem 11 shows that for balanced long brooms ∆n,k = Ω(n2 ). We call the set of brooms that are not long brooms as medium brooms where k ≥ n/2. We call the medium brooms where n − k = Ω(n) ∧ k = Ω(n) as long-medium brooms. A similar analysis
Sorting permutations with a transposition tree
19
shows that for long-medium brooms ∆n,k = Ω(n2 ). We call the set consisting of balanced long brooms and long-medium brooms as non-short brooms. Thus, for non-short brooms when n ≥ 6, ∆n,k = Ω(n2 ); it follows that β − λ = Ω(n2 ). There are Ω(n) such trees. Theorem 12 There exist Ω(n2 ) trees where β − γ = β − δ ′ = Ω(n2 ). Proof. We compute γ and β on a balanced double broom. Similar to a broom, for a balanced double broom γ and δ ′ have the same value. The computation of γ (or δ ′ ) proceeds by deleting all p left-spokes at the cost of p∗ (n− k − p+ 1). Then we obtain a k broom whose value for γ is given by Theorem 11. Simplifying, the value of γ = (n2 − p2 − 2nk + k 2 + n − p + 2k − 3)/2. The computation of β proceeds by deleting p pairs that are n − k − p + 1 apart at the cost of 2p ∗ (n − k − p + 1) − 2p. Then we obtain a broom with n − 2p vertices and k − p spokes, whose β is given by Theorem 11. Simplifying, the value of β = n2 /2 − p2 − k 2 − n/2 + k. Thus, ∆n,p,k ≈ nk − (p2 + 3k 2 )/2. Recall that n > 2k + p + 1, so, ∆n,p,k > k 2 /2 = Ω(n2 ). Further, for each value of n − p − k there are Ω(n) choices for p and k together and there are Ω(n) choices for n − p − k. Thus, there exist Ω(n2 ) such trees. 5.3
Implementation results
We computed the bounds γ, δ ′ and β [17] on a set of trees where no two of them are isomorphic. The Sage application was used to enumerate all non-isomorphic trees for a given number of vertices [29]. Johnson-Trotter Algorithm was used to generate permutations [27]. For computing f (Γ ), we referred to [10]. Based on the choices made by the algorithm to compute β, for certain trees β < f (Γ )[17]. Our implementation shows that for all trees β = f (Γ ), thus β that we computed happens to be βmax , an upper bound [17]. Table 3 shows the number of vertices, the corresponding number of trees, and the cumulative sum of the parameters λ, δ ′ , γ, β and f (Γ ) respectively for all trees with a given number of vertices. In the ′ context of implementation results, δ ′ refers to δv2 . If we sort these parameters by decreasing performance then we obtain (λ, δ ′ , γ, β). Recall that λ = min(δ ′ , γ). For trees with six or seven vertices there was no instance in which β was tighter than either δ ′ or γ. The bound δ is intended to demonstrate a measure that is deterministic, we do not show the corresponding implementation results which are marginally worse than f (Γ ). In trees with eight and nine vertices there was one instance each where β was one less than γ. In trees with ten vertices there were eight instances where β was one less than γ.
6
Introduction to strings and conclusions
A string is a sequence in which symbols can repeat. We consider the case where at least one symbol repeats, otherwise a string boils down to a permutation. A set of strings that can be transformed into each other with a transposition tree T
20
Bhadrachalam Chitturi
Table 3. Cumulative values of λ, δ ′ , γ, β and f (Γ ) for a given number of vertices Vertices 6 7 8 9 10
Trees 6 11 23 47 106
λ 63 153 407 1027 2802
δ′ 63 153 407 1028 2809
γ 63 154 409 1033 2821
β 68 165 434 1116 3020
f (Γ ) 68 165 434 1116 3020
are similar to each other. Given a set of symbols s1 , s2 , . . . sn where ∃i6=j si = sj , any two permutations of the symbols of this set yield a a pair of similar strings. Transforming strings is a widely studied area, for a good survey, please refer to Fertin et al. [15]. Several dissertations were written in this area [4] [12]. Theorem 13 γ is an upper bound to transform any string of length n into any other similar string with a transposition tree T , where |VT | = n . Proof. Consider two arbitrary similar strings S1 and S2 of length n. Let S1 be the source string, S2 be the destination string and the corresponding transposition tree with n vertices be T . In any iteration Algorithm G identifies a recluse say u, deletes it and increments γ by ecc(u). In the first iteration let vertex u be the chosen recluse. Here we have two cases: Case 1: u is a repeated symbol in S1 and Case 2: u is not repeated. In Case 1 we have two subcases: either all copies of the symbol u are ecc(u) apart from vertex u or at least one of the copy is at a distance less than ecc(u) from vertex u. In the first subcase we increment γ by the required number of moves i.e. ecc(u) and in the latter subcase, γ overestimates the required number of moves. Similarly, in Case 2, γ is incremented with the required number of moves for the corresponding homing or it is an overestimate. This property remains invariant for subsequent iterations. Thus, γ is an upper bound for strings. Proofs similar to the proof of Theorem 13 show that δ ′ and λ are also upper bounds for sorting strings. Consider the case where T is a bubble sort graph of length n given by {(1,2), (2,3),. . . (n-1,n)}. When permutations are sorted with T , the reverse order permutation i.e (n, n − 1, . . . 1) requires n2 moves which equals diam(Γ ). Let the source string S1 be (n − 1, n − 1, n − 2, n − 3, . . . 1) and let the destination string S2 be (1, 2, 3, . . . , n − 2, n − 1, n − 1). It can be shown that this scenario is the worst case for transforming a string into another similar string with T . However, S1 can be transformed into S2 in at most n2 − 1 moves. This corresponds to homing the rightmost n − 1 to vertex n (the recluse) in n − 2 moves followed by homing the leftmost n − 1 to vertex n − 1 in n − 2 moves followed by homing the sequence of vertices given by: (n − 2, n − 3, . . . 1). Thus, there are cases where an upper bound for sorting permutations is strictly greater than the corresponding upper bound for transforming strings with a given transposition tree T .
Sorting permutations with a transposition tree
6.1
21
Conclusions
We computed upper bounds γ and δ ′ for sorting permutations with a given transposition tree T in polynomial time by directly working with T , thereby avoiding the examination of the permutations. These upper bounds are also upper bounds for diam(Γ ) the diameter of the corresponding Cayley graph. Our bounds are easy to comprehend and we eschewed artificial means of handling specific types of trees. Our implementation results show that for 6 ≤ |VT | ≤ 10, γ and δ ′ are tighter than β [17] and f (Γ ) [1] on average and in most of the cases. For any sufficiently large complete binary tree we derived tight estimates of β, γ and δ ′ and showed that β − γ, β − δ ′ , f (Γ ) − γ and f (Γ ) − δ ′ are Ω(n). For a bubble sort graph, the sparsest of all trees, all the upper bounds equal diam(Γ ). For non-short brooms and balanced double brooms β and f (Γ ) exceed γ (resp. δ ′ ) by Ω(n2 ). Obtaining tight estimates of β, γ and δ ′ , for other trees enables a more comprehensive comparison. We call an upper bound κ relatively order optimal with respect to another upper bound χ for a particular tree T if χ(T ) − κ(T ) = θ(diam(Γ )). γ (resp. δ ′ ) is relatively order optimal with respect to β and f (Γ ) for non-short brooms and balanced double brooms. Future work can focus on designing tighter upper bounds. The transformation of strings with transposition trees is an open area. As shown by Theorem 13, the upper bounds computed in this article might not be tight for strings. That is, given n, k (the number of symbols), and (r1 , r2 , . . . , rk ) where ri is the minimum number of copies of the symbol i; a tighter upper bound may be obtained [28]. Consider computing γ on a double broom with the corresponding algorithm Aγ . A double broom can be viewed as two stars connected with a path graph that connects their centres. For the first few iterations, in each iteration, Aγ proceeds by deleting a spoke of the star with lesser number of spokes and updating γ: γ ← γ + ecc(u) where ecc(u) = diam(T ). After a few such iterations, as a side effect of homing markers, new markers arrive at the other star. For certain double brooms, one can prove that by carefully directing these incoming markers one can improve upon γ. Thus, a greedy method such as Aγ can be improved upon for certain trees [9].
7
Acknowledgements
Amma was the inspiration for this project. We thank Rajan Sundavaradhan for helpful discussions and suggestions. We thank Nithin Nagaraj for interesting discussions on possible applications of this work. Jayakumar P. helped in computing f (Γ ) [1]. Ashwin Ganesan introduced this problem to us and informed us about www.sagemath.org. Ganesh Sundaram and D. Kim helped with LaTex installation and features. We thank an anonymous reviewer for helpful suggestions.
22
Bhadrachalam Chitturi
References 1. S. B. Akers and B. Krishnamurthy. A group-theoretic model for symmetric interconnection networks. IEEE Transactions on Computers, 38(4):555–566, 1989. 2. L. Bulteau, G. Fertin and I. Rusu. Pancake Flipping Is Hard. LNCS, SpringerVerlag, 7464:247–258, 2012. 3. S. C. Bruell. Self-Stabilizing Algorithms for Finding Centers and Medians of Trees. SIAM Journal of Computing, 29(2):600–614, 1999. 4. B. Chitturi. On transforming sequences. Ph.D. Thesis, Department of Computer Science, University of Texas at Dallas, 2007. 5. B. Chitturi, H. Sudborough, W. Voit and X. Feng. Adjacent Swaps on Strings. LNCS, Springer-Verlag, 5092:299–308, 2008. 6. B. Chitturi, W. Fahle, Z. Meng, L. Morales, C. O. Sheilds, I. H. Sudborough and W. Voit. An (18/11)n upper bound for sorting by prefix reversals. Theoretical Computer Science, 410(36): 3372-3390, 2009. 7. B. Chitturi. A note on Complexity of Genetic Mutations. Discrete Mathematics Algorithms and Applications, (3)(3):269-286, 2011. 8. B. Chitturi and I. H. Sudborough. Bounding Prefix Transposition Distance for Strings and Permutations. Theoretical Computer Science, (421):15-24, 2012. 9. B. Chitturi. A short note on sorting permutations with brooms. Technical Report, University of Texas at Dallas, UTDCS-11-13, 2013. 10. http://www.codechef.com/ 11. T. H. Cormen, C. E. Leiserson, R. L. Rivest. Introduction To Algorithms. The second edition. The MIT Press, 2001. 12. G. Cormode. Sequence Distance Embeddings. Ph.D. thesis, University of Warwick, 2003. 13. D. Z. Du and F. Hsu. Combinatorial Network Theory. Applied Optimization Series, Springer, 1995. 14. X. Feng, B. Chitturi, and H. Sudborough. Sorting Circular Permutations by Bounded Transpositions. Advances in Experimental Medicine and Biology, SpringerVerlag, 680(7):725–736. 15. G. Fertin, A. Labarre, I. Rusu, E. Tannier and S. Vialette. Combinatorics of Genome Rearrangements. The MIT Press 2009. 16. A. Ganesan. On the strictness of a bound for the diameter of Cayley graphs generated by transposition trees. Communications in Computer and Information Science, 283:54–61, 2012. 17. A. Ganesan. An efficient algorithm for the diameter of Cayley graphs generated by transposition trees. IAENG International Journal of Applied Mathematics 42:4, 2012. 18. W. H. Gates and C. H. Papadimitriou. Bounds for sorting by prefix reversal. Discrete Mathematics, 27(1):47–57, 1979. 19. M. C. Heydemann, N. Marlin and S. Prennes. Complete Rotations in Cayley Graphs. Eur. J. Comb., 22(2): 179–196,2001. 20. M. C. Heydemann. Cayley graphs and interconnection networks. In Graph Symmetry: Algebraic Methods and Applications, pages 167–226. Kluwer Academic Publishers, Dordrecht, 1997. 21. C. Hurkens, L. van Iersel, J. Keijsper, S. Kelk, L. Stougie and J. Tromp. SIAM Journal on Discrete Mathematics, 21(3):592–611, 2007. 22. M. Jerrum. The complexity of finding minimum length generator sequences. Theoretical Computer Science, 36:265–289, 1985.
Sorting permutations with a transposition tree
23
23. D. E. Knuth. The Art of Computer Programming, Volume 3: Sorting and Searching. Addison-Wesley Publishing Company, 1973. 24. S. Lakshmivarahan, J-S. Jho and S. K. Dhall. Symmetry in interconnection networks based on Cayley graphs of permutation groups: A survey. Parallel Computing, 19:361–407, 1993. 25. L. Morales and H. Sudborough. Comparing Star and Pancake Networks. LNCS, 2566:18–36, 2002. 26. A. B. Murdasov. A simple algorithm for finding the center of a tree. Cybernetics and Systems Analysis, 12(1):157–158, 1976. 27. http://www.notesandreviews.com/ 28. A.J. Radcliffe, A.D. Scott and E.L. Wilmer. Reversals and transpositions over finite alphabets. SIAM Journal on Discrete Mathematics, 19(1):224-244, 2005. 29. http://www.sagemath.org/ 30. J. H. Smith. Factoring, into Edge Transpositions of a Tree, Permutations Fixing a Terminal Vertex. Journal of Combinatorial Theory, 85(A):92–95, 1999. 31. J. Xu. Topological Structure and Analysis of Interconnection Networks. Kluwer Academic Publishers, 2001.