Discrete Applied Mathematics

Size: px
Start display at page:

Download "Discrete Applied Mathematics"

Transcription

1 Discrete Applied Mathematics 159 (011) Contents lists available at ScienceDirect Discrete Applied Mathematics journal homepage: Recursive merge sort with erroneous comparisons Petros Hadjicostas a,, K.B. Lakshmanan b a Department of Mathematics and Statistics, Texas Tech University, Box 4104, Lubbock, TX , USA b Department of Computer Science, The College at Brockport, State University of New York, Brockport, NY 1440, USA a r t i c l e i n f o a b s t r a c t Article history: Received 10 November 009 Received in revised form May 011 Accepted 4 May 011 Available online June 011 Keywords: Analysis of algorithms Comparisons Errors Inversions Measures of disarray Runs Sorting Recursive merge sort In this paper, we analyze the recursive merge sort algorithm and quantify the deviation of the output from the correct sorted order if the outcomes of one or more comparisons are in error. The disorder in the output sequence is quantified by four measures: the number of runs, the smallest number of integers that need to be removed to leave the sequence sorted, the number of inversions, and the smallest number of successive exchanges needed to sort the sequence. For input sequences whose length is large compared to the number of errors, a comparison is made between the robustness to errors of bubble sort, straight insertion sort, and recursive merge sort. 011 Elsevier B.V. All rights reserved. 1. Introduction In this paper, we analyze the recursive merge sort algorithm when some of the outcomes of one or more comparisons are in error and examine by how much the output will deviate from the correct sorted order. By an error, we mean the outcome of a binary comparison between two data elements is no when factually it should be yes, and vice versa. For a comprehensive review of the literature in the field of analyzing search and sort algorithms to cope with possible errors in comparisons, see [1,9]. Islam and Lakshmanan [14] analyzed several sort algorithms under the assumption that the outcome of exactly one comparison is in error. Hadjicostas and Lakshmanan [1,13] analyzed bubble sort and straight insertion sort under the assumption that the outcomes of several comparisons are in error. In this paper, we perform a similar analysis for recursive merge sort. Bagchi [3], Lakshmanan et al. [17] and Ravikumar [] have studied fault-tolerant algorithms for sorting with a worst case upper bound on the number of erroneous comparisons, while Yao and Yao [4] and Leighton and Ma [18,19] have studied fault-tolerant sorting networks. Alonso et al. [1] have performed a probabilistic analysis of quicksort when some comparisons are unreliable. Finocchi and Italiano [11] investigate the design and analysis of algorithms resilient to memory faults. They prove, for example, that any O(n log n) comparison-based sorting algorithm can tolerate the corruption of at most O((n log n) 1/ ) keys; see also [8,10]. For a more thorough review of the literature before 005, see the introduction in [1]. Let a = (a 1, a,..., a n ) be a list consisting of n distinct integers. Assume that the correct order for sorting is the ascending one. The degree of disorder or disarray of the list a can be quantified in a variety of ways; see, for example, [4 7,16,0]. Corresponding author. Tel.: ; fax: address: petros.hadjicostas@ttu.edu (P. Hadjicostas) X/$ see front matter 011 Elsevier B.V. All rights reserved. doi: /j.dam

2 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) We can use the number of runs in a, the smallest number of elements in a that should be removed from a to leave it sorted, the number of inversions in a, and the smallest number of successive exchanges of elements in a needed to sort a. By a run in a we mean a non-descending sublist of consecutive elements in a, say (a i, a i+1,..., a m ), such that a i is not preceded by a smaller number, and a m is not followed by a larger number. For a sorted list a the number of runs is 1, while for a list a with n elements in reverse order the number of runs is n. The smallest number of integers that should be removed from a list a of n elements to leave it sorted is 0 for a sorted list, while this number equals n 1 for a list a in reverse order. By inversion in a we mean a pair of integers in a in the wrong order. For a sorted list a the number of inversions is 0, while for a sequence a in reverse order the number of inversions is n(n 1)/. It is known that the smallest number of successive exchanges of elements in a needed to sort a is n minus the number of cycles in a (when a is considered as a permutation of the first n positive integers); see, for example, [16, Ex. 5..-, pp. 134 and 68]. A sorted sequence has a smallest number of exchanges equal to 0, while a sequence in reverse order has a smallest number of exchanges equal to n/. The list a = (n, 1,,..., n 1) has a smallest number of exchanges equal to n 1, which is the highest possible. Let N = {0, 1,,...} be the set of nonnegative integers. For a finite set A, let #A denote the number of elements of A. For each n N \ {0}, let A n be the set of all lists with n distinct integers as elements. For a list a A n, let R(a) and I(a) be the number of runs and the number of inversions, respectively, in a. Let also RM(a) be the smallest number of integers that should be removed from a to leave it sorted, and EX(a) be the smallest number of successive exchanges of elements in a needed to leave it sorted. The organization of the paper is as follows. In Section, we review merging of two sequences and recursive merge sort. In Section 3, we introduce some necessary notation (needed for the results of the paper) and prove some preliminary results about recursive merge sort when some of its comparisons are erroneous. In Section 4, we discuss the complement (or conjugate) of a sequence of integers, and we prove the existence of the complement of recursive merge sort with some erroneous comparisons. In Sections 5 8, we prove some results about the maximum and minimum of the four measures of disorder (R( ), RM( ), I( ) and EX( )) for the output sequence of recursive merge sort operating on sequences with fixed length n and having a fixed number of erroneous comparisons e. Finally, in Section 9 we give some concluding remarks and compare the performance of recursive merge sort with bubble sort and straight insertion sort when the number of erroneous comparisons is fixed and small compared to the length of the sequences on which the sorting algorithms operate. Since the version of merge sort we examine is recursive, most of the proofs in this paper are inductive.. Recursive merge sort The following pseudo-code describes how the merging of two sorted sequences works (when there are no errors in comparisons). procedure merge // Merge a[1], a[],..., a[p] and // b[1], b[],..., b[q] to produce // c[1], c[],..., c[p+q] { ia = 1; ib = 1; ic = 1; while (ia <= p and ib <= q) { if (a[ia] < b[ib]) { c[ic] = a[ia]; ia = ia + 1; ic = ic + 1; } else { c[ic] = b[ib]; ib = ib + 1; ic = ic + 1; }} if (ia > p) while (ib <= q) { c[ic] = b[ib]; ib = ib + 1; ic = ic + 1; } else while (ia <= p) { c[ic] = a[ia]; ia = ia + 1; ic = ic + 1; }} To describe the merging with words, let a = (a 1, a,..., a p ) A p and b = (b 1, b,..., b q ) A q be two sorted sequences to be merged into a single sequence c = (c 1, c,..., c p+q ), which will be sorted in ascending order. When there are no errors in comparisons, the merging is performed as follows: the smallest element of a, i.e. a 1, is compared with the smallest element of b, i.e. b 1. The minimum of these two numbers is assigned as a value for c 1 ; if this minimum is a 1, then the rest of a, i.e. (a,..., a p ) is compared with b in the same way; otherwise, if the minimum is b 1, then a is compared with the rest of b, i.e. (b,..., b q ) in the same way. In the first case, min(a, b 1 ) is assigned as a value for c ; in the second case, min(a 1, b ) is assigned as a value for c. This procedure continues until one of the two lists is left empty. In such a case, the (remaining) elements of the non-empty list are put at the end of the output list c. The following pseudo-code describes how recursive merge sort works (when there are no errors in comparisons). procedure mergesort // Sort a[first], a[first+1],..., a[last] { if (first < last)

3 1400 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) { mid = floor((first + last-1)/); mergesort a[first], a[first+1],..., a[mid]; mergesort a[mid+1], a[mid+],..., a[last]; merge a[first], a[first+1],..., a[mid] and a[mid+1], a[mid+],..., a[last] to produce a[first], a[first+1],..., a[last]; }} To describe recursive merge sort with words, let d = (d 1,..., d n ) A n (where n N \ {0, 1}). We break this list into two lists of approximately equal lengths: d 11 = (d 1,..., d s ) of length s = n/ and d 1 = (d s+1,..., d n ) of length n s = n/. Each of the two sublists, d 11 and d 1, will be sorted individually, and the outputs c 11 and c 1 will be merged into the final output list c according to the merging algorithm above. Provided s > 1, we use recursive merge sort on list d 11 by breaking it into two sublists of approximately equal length: d 1 = (d 1,..., d t ) of length t = s/ and d = (d t+1,..., d s ) of length s t = s/. Each of these sublists is sorted individually, and the outputs c 1 and c are merged into the output list c 11. In a similar way, provided n s > 1, we use recursive merge sort on list d 1, and break it into two sublists of approximately equal length: d 3 = (d s+1,..., d s+r ) of length r = (n s)/ and d 4 = (d s+r+1,..., d n ) of length n s r = (n s)/. Each of these sublists is sorted individually, and the outputs c 3 and c 4 are merged into the output list c 1. Each of the lists d 1, d, d 3, and d 4 is sorted using recursive merge sort, and so on. Note that a list consisting of only one integer does not require further action for sorting. 3. Notation and preliminary results about recursive merge sort If a A n, let ranks(a) = (ρ 1, ρ,..., ρ n ) be the list of ranks of the elements of a, where the smallest number gets the smallest rank. In other words, for 1 i n, ρ i is the rank of the ith element of a. Obviously, ranks(a) is a permutation of the integers 1,,..., n. For each n N \ {0} and each d A n, let ME n (d) be the set of all executions of recursive merge sort that can operate on list d (whose length is n) such that some or all of the comparisons of some or all the mergings of transformed sublists of d maybe in error. (If there are no errors in comparisons, then the transformed sublists of d to be merged are all sorted.) For each d A n and M ME n (d) let Me(M) be the number of mergings of transformed sublists of d needed when M operates on d; C(M) be the number of comparisons in all mergings in M; and E(M) be the total number of erroneous comparisons in all mergings in M. Finally, denote by out(m, d) the output list of the application of M on d. When n = 1 and d A 1, then ME 1 (d) contains only one execution M of recursive merge sort that does nothing on d. In such a case, we have Me(M) = 0, C(M) = 0 and E(M) = 0. When n, execution M ME n (d) breaks list d A n into two lists: d 11 = (d 1,..., d s ) of length s = n/ and d 1 = (d s+1,..., d n ) of length n s = n/. In addition, execution M is such that, each of the two sublists, d 11 and d 1, is acted upon by some executions M 11 ME s (d 11 ) and M 1 ME n s (d 1 ). These executions are subexecutions of M, and the corresponding outputs c 11 and c 1 will be merged into the final output list c according to M. The list [(d 11, M 11, c 11 ), (d 1, M 1, c 1 )] is called the first pass of M. Given n N \ {0}, we define the relation n on A n as follows: d n f ranks(d) = ranks(f ) for all d, f A n. Obviously, n is an equivalence relation on A n. For each d A n define by [d] n the equivalence class of d. Since the merging (with possible errors in some comparisons) of two sequences a = (a 1,..., a p ) A p and b = (b 1,..., b q ) A q with {a 1,..., a p } {b 1,..., b q } = only depends on the relative positions of the numbers a 1,..., a p, b 1,..., b q in the output sequence, and not on the actual values of the numbers, we conclude the following: given n N \ {0}, d A n, and M ME n (d), for any f [d] n, execution M operates on the sequence f in exactly the same way that it operates on sequence d. In addition, ME n (d) = ME n (f ) and out(m, f ) [out(m, d)] n. We next introduce the idea of a permutation function. The symbol n denotes composition of lists of length n: if d, f A n and ranks(f ) = (r 1,..., r n ), then we define d n f = d n (r 1,..., r n ) = (d r1,..., d rn ). It can be proven that n is associative on A n. A function σ : A n permutation β of the numbers 1,,..., n such that σ (a) = a n β (1) A n is called a permutation function if there exists a () for all a A n. Lemma 3.1. (a) Let p, q N \ {0}. If a A p, b A q, ζ is a permutation of the numbers 1,..., p, and η is a permutation of the numbers 1,..., q, then (a p ζ, b q η) = (a, b) p+q (ζ, η + p), where η + p := (η 1 + p,..., η q + p). (b) Let n N \ {0} and σ : A n A n be a permutation function. Then σ (f ) [σ (d)] n for all f, d A n with f [d] n.

4 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) Proof. (a) Let g = (a, b). Then g i = a i for i = 1,..., p, and g i+p = b i for i = 1,..., q. Then (a p ζ, b q η) = (a ζ1,..., a ζp, b η1,..., b ηq ) = (g ζ1,..., g ζp, g η1 +p,..., g ηq +p) = g p+q (ζ, η + p). (b) Let f, d A n with f [d] n. Let (r 1,..., r n ) = ranks(f ) = ranks(d). By assumption, there is a permutation β of the numbers 1,,..., n such that σ (f ) = f n β = (f β1,..., f βn ) and σ (d) = d n β = (d β1,..., d βn ). Then ranks(σ (f )) = (r β1,..., r βn ) = ranks(σ (d)). The following lemma associates a permutation function σ : A n A n with each execution of a recursive merge sort. It will be used in Section 4 for the construction of the complement (conjugate) of an execution of recursive merge sort. Lemma 3.. Let n N \ {0}, d A n, and M ME n (d). Then there is a unique permutation function σ M : A n A n such that σ M (d) = out(m, d). In addition, σ M (f ) = out(m, f ) for all f [d] n. Proof. If c := out(m, d), then c is a permutation of d, i.e., there is a permutation β of the numbers 1,..., n such that d n β = c. Define σ M : A n A n by σ M (h) = h n β for all h A n. Then σ M (d) = d n β = c = out(m, d). Let f [d] n. By Lemma 3.1(b), σ M (f ) [σ M (d)] n = [c] n. Also, out(m, f ) [out(m, d)] n = [c] n. Thus, f n β = σ M (f ) [out(m, f )] n. Since both f n β = σ M (f ) and out(m, f ) are permutations of f, we conclude that σ M (f ) = out(m, f ). Suppose now that σ M : A n A n is another permutation function of M such that σ M (d) = out(m, d) = c. Then there is a permutation γ of the numbers 1,..., n such that σ (h) = h n γ for all h A n. Then d n β = c = d n γ, i.e., (d β1,..., d βn ) = (d γ1,..., d γn ). Thus, β i = γ i for i = 1,,..., n, so σ M = σ M. Theorem 3.3. Let n N \ {0}, d A n and M ME n (d) be given. Then Me(M) = n 1 and 0 C(M) W(n), where the sequence (W(n) : n = 1,,...) satisfies n n W(n) = W and W(1) = 0. In addition, + W W(n) = nq (n) Q (n) + 1, where Q (n) = log (n + 1). + n 1, n, (3) Proof. We prove Me(M) = n 1 and C(M) W(n) by induction on n. If n = 1, then Me(M) = 0 = 1 1 and C(M) = 0 = W(1). Let n and assume for all integers m with 1 m < n, all d Am, and all M ME m ( d), we have Me( M) = m 1 and C( M) W(m). Let d = (d1,..., d n ) A n and M ME n (d). Suppose execution M breaks list d into two lists: d 11 = (d 1,..., d s ) of length s = n/ and d 1 = (d s+1,..., d n ) of length n s = n/. In addition, execution M is such that, each of the two sublists, d 11 and d 1, is acted upon by some executions M 11 ME s (d 11 ) and M 1 ME n s (d 1 ). The corresponding outputs c 11 and c 1 will be merged into the final output list c according to M. Since 1 s = n/ < n and 1 n s = n/ < n, we have Me(M 11 ) = s 1, Me(M 1 ) = n s 1, C(M 11 ) W(s) and C(M 1 ) W(n s) by the induction hypothesis. We have Me(M) = Me(M 11 ) + Me(M 1 ) + 1 = s 1 + n s = n 1. Since the merging of d 11 and d 1 according to M requires at most n 1 comparisons, n n C(M) C(M 11 ) + C(M 1 ) + n 1 = W + W + n 1 = W(n), and the inductive step is complete. For a proof of (4), see Section 4.6 in []. Remark 3.4. Recurrence (3) for the upper bound of the number of comparisons of an execution M of recursive merge sort appears in a number of books about sorting; e.g., see Section 4.6 in []. Here we provide a proof that is valid for all executions M for which some of their comparisons may be in error. The following lemma is needed in the proof of Theorem 3.6, which is one of the main results of the section. Lemma 3.5. Let the sequence (W(n) : n = 1,,...) be defined as in the statement of Theorem 3.3. For each n N \ {0}, there is d A n and M ME n (d) such that E(M) = W(n) and the final output sequence of the application of M on d is c = (n, n 1,..., 1). Proof. We prove the lemma by induction on n. For n = 1, let d = (1) A 1 and let M ME 1 (d) be such that it does nothing on d. Then E(M) = 0 = W(1) and the final output is c = (1) = d. (4)

5 140 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) Let n, and assume that the statement of the lemma is true for all integers m with 1 m < n. Let s = n/, and thus n s = n/. If n is odd, then n = s + 1, s = (n 1)/ and n s = (n + 1)/. By the induction hypothesis, there are d1 A s, d A n s, M1 ME s ( d1 ) and M ME n s ( d ) such that E( M1 ) = W(s), E( M ) = W(n s), the application of M1 on d1 yields c 1 = (s, s 1,..., 1) and the application of M on d yields c = (n s, n s 1,..., 1). Without loss of generality, we may assume that d1 is a permutation of (, 4,..., s) and d is a permutation of (1, 3,..., s + 1). Denote these new sequences by d3 and d4, respectively. The corresponding outputs will then be c 3 = (s, s,..., ) and c 4 = (s + 1, s 1,..., 1). Let d = ( d3, d4 ), and assume that M ME n ( d) such that it breaks d into d3 and d4, applies M1 on d3, applies M on d4, and then merges the outputs c 3 and c 4 with exactly n 1 comparisons, all of which are erroneous. It is then easy to see that the output is (n, n 1, n,..., 1) and E( M) = E( M1 ) + E( M ) + n 1 = W(s) + W(n s) + n 1 = W(n). A similar proof can be given for the case when n is even. Thus the statement of the lemma is true for n, and the induction proof is complete. Theorem 3.6. Let the sequence (W(n) : n = 1,,...) be defined as in the statement of Theorem 3.3. For each pair of integers (n, e) such that n 1 and 0 e W(n), we have A(n, e) := {(d, M) : d A n, M ME n (d), and E(M) = e}. (5) Proof. We prove the theorem by induction on n. For n = 1, we have 0 e W(1) = 0, and A(n = 1, e = 0) contains only one pair (d, M) with d A 1, M ME 1 (d) and E(M) = 0 = e. Let n, and assume that for all integers m and e with 1 m < n and 0 e W(m) we have A(m, e). Let ϵ be an integer such that 0 ϵ W(n). Define s = n/, in which case n s = n/. We consider two cases: (a) 0 ϵ W(s) + W(n s); (b) W(s) + W(n s) + 1 ϵ W(n). (a) Assume that 0 ϵ W(s) + W(n s). In such a case, we can find integers ϵ 1 and ϵ such that ϵ 1 + ϵ = ϵ, 0 ϵ 1 W(s), and 0 ϵ W(n s). By the induction hypothesis, there are d 1 A s, d A n s, M 1 ME s (d 1 ) and M ME n s (d ) such that E(M 1 ) = ϵ 1 and E(M ) = ϵ. Without loss of generality, we may assume that d 1 is a permutation of the numbers 1,..., s and d is a permutation of the numbers s + 1,..., n. Let c 1 and c be the outputs of the action of executions M 1 and M on d 1 and d, respectively. Let d = (d 1, d ) A n, and assume that M breaks d into d 1 and d, applies execution M 1 on d 1, applies execution M on d, and then merges outputs c 1 and c with no errors in comparisons. Then M ME n (d) and E(M) = E(M 1 ) + E(M ) + 0 = ϵ 1 + ϵ = ϵ. In such a case, A(n, ϵ). (b) Assume that W(s) + W(n s) + 1 ϵ W(n), and let ϵ = ϵ W(s) W(n s). Then 1 ϵ n 1. We consider two subcases: (i) n is an even integer; (ii) n is an odd integer. (b)(i) Assume that n is even, in which case n = s = (n s). By Lemma 3.5, there are d1 A s and M1 ME s ( d1 ) such that E( M1 ) = W(s) and the application of M1 on d1 yields c 1 = (s, s 1,..., 1). Without loss of generality, we may assume that d1 is a permutation of (1, 3,..., s 1) or that d1 is a permutation of (, 4,..., (n s)). Denote these new d1 s by d and d3, respectively. In such a case, when M1 is applied to d the output is c = (s 1, s 3,..., 1) = (n 1, n 3,..., 1), and when M1 is applied to d3 the output is c 3 = ((n s), (n s),..., ) = (n, n,..., ). Let d = ( d, d3 ) A n and assume that M ME n (d) such that it breaks d into d and d3, applies M1 on d, applies M1 on d3, and then merges the outputs c and c 3 such that the first ϵ comparisons are in error, while the rest are not in error. In such a case, the output is c = (s, s 1, s,..., s ϵ + 1, 1,, 3,..., s ϵ). (If ϵ = n 1, then c = (s, s 1,...,, 1).) Then E( M) = E( M1 ) + ϵ = W(s) + ϵ = ϵ. In such a case, A(n, ϵ). (b)(ii) Using a similar argument as in case (b)(i), we can prove that A(n, ϵ) when n is odd. Thus the induction step is complete, and so is the proof of the theorem. Theorem 3.6 allows us to state the following definitions. For each n N \ {0}, d A n, and M ME n (d), let: (a) R(d, M) be the number of runs in the output list after M operates on d;

6 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) (b) RM(d, M) be the smallest number of integers that should be removed from the output sequence, after M operates on d, to leave it sorted; (c) I(d, M) be the number of inversions in the output list after M operates on d; (d) EX(d, M) be the smallest number of successive exchanges needed to sort the output list after M operates on d; We then have the following inequalities: (a) 1 R(d, M) n; (b) 0 RM(d, M) n 1; (c) 0 I(d, M) n(n 1)/; (d) 0 EX(d, M) n 1. For the integers n and e with n 1 and 0 e W(n), using (5), we define: Mruns(n, e) = max{r(d, M): (d, M) A(n, e)}; mruns(n, e) = min{r(d, M): (d, M) A(n, e)}; Mrem(n, e) = max{rm(d, M): (d, M) A(n, e)}; mrem(n, e) = min{rm(d, M): (d, M) A(n, e)}; Minv(n, e) = max{i(d, M): (d, M) A(n, e)}; minv(n, e) = min{i(d, M): (d, M) A(n, e)}; Mexc(n, e) = max{ex(d, M): (d, M) A(n, e)}; mexc(n, e) = min{ex(d, M): (d, M) A(n, e)}. For example, Mruns(n, e) and mruns(n, e) represent the worst and the best case scenario, respectively, for the number of runs in the output list obtained when an execution of recursive merge sort with exactly e errors in comparisons operates on a list of integers with length n. 4. Complementarity results For n N \ {0} let a A n and ranks(a) = (r 1, r,..., r n ). Consider the list a A n, called the complement of a, which is created by putting in the ith position the element of a whose rank is n + 1 r i. Then ranks(a) = (n + 1 r 1, n + 1 r,..., n + 1 r n ). Kendall [15, p. 11] calls such sequences a and a as conjugate. If a (1), a (),..., a (n) are the order statistics of a 1,..., a n, i.e., a (i) is the ith smallest number in the list a, then let a r = (a (n), a (n 1),..., a (1) ) be the elements of a is reverse sorted order. Then using the composition symbol n defined in (1) we have a = a r n a. For example, if a = (4, 1, 1, 0), then ranks(a) = (3, 4,, 1), ranks(a) = (, 1, 3, 4), and a = (1, 0, 4, 1). Also, a r = (1, 4, 1, 0) and a r a = (a r, 3 ar, 4 ar, ar 1 ) = (1, 0, 4, 1) = a. The following lemma gives some complementarity results for the four measures of disarray we study. It is proven in Hadjicostas and Lakshmanan [13, Lemma 5.1], even though some parts of it are probably known for decades. Lemma 4.1. (i) R(a) = n + 1 R(a); (ii) I(a) = n(n 1)/ I(a); (iii) RM(a) n 1 RM(a). (iv) EX(a) n/ EX(a). In (iii) and (iv), when ranks(a) = (1,,..., n), the inequality holds as equality. The following lemma shows what happens to the complement (conjugate) of a list c when we break c into two sublists. It is needed in the construction of the complement of an execution of recursive merge sort. Lemma 4.. Let n N \ {0, 1}, c = (c 1,..., c n ) A n and c = α = (α 1,..., α n ) A n. If we write c = (c 1, c ) and α = (α 1, α ), where c 1 = (c 1,..., c k ) A k, c = (c k+1,..., c n ) A n k, α 1 = (α 1,..., α k ) A k and α = (α k+1,..., α n ) A n k, then ranks(c 1 ) = ranks(α 1 ) and ranks(c ) = ranks(α ); i.e., α 1 [c 1 ] k and α [c ] n k. Proof. Let ranks(c) = (r 1,..., r n ), ranks(c 1 ) = (s 1,..., s k ) and ranks(α 1 ) = (ω 1,..., ω k ). Since ranks(c 1 ) = (k + 1 s 1,..., k + 1 s k ), to prove that ranks(c 1 ) = ranks(α 1 ), we need to show that ω i = k + 1 s i for i = 1,..., k. Since r 1,..., r k are the first k ranks in ranks(c), we have r j < r m s j < s m

7 1404 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) for 1 j < m k. Since ranks(α) = (n + 1 r 1,..., n + 1 r n ), for 1 i < l k, we have (ω i < ω l ) (α i < α l ) (n + 1 r i < n + 1 r l ) (r i > r l ) (s i > s l ) (k + 1 s i < k + 1 s l ). Since also the lists (ω 1,..., ω k ) and (k+1 s 1,..., k+1 s k ) are both permutations of (1,..., k), we have (ω 1,..., ω k ) = (k + 1 s 1,..., k + 1 s k ). A similar argument can be used to prove that ranks(c ) = ranks(α ). Lemma 4.3. Let p, q N \ {0}, a A p and b A q with {a 1,..., a p } {b 1,..., b q } =. Let f A p and g A q be such that they have no numbers in common and (f, g) [(a, b)] p+q. Then: (a) f [a] p and g [b] q. (b) If it is possible to merge a and b with exactly δ comparisons, out of which exactly ϵ are erroneous, then it is possible to merge f with g with exactly δ comparisons, out of which exactly δ ϵ are erroneous, such that each comparison in the merging of a and b is erroneous if and only if the corresponding comparison in the merging of f and g is not erroneous. If c A p+q is the output of the merging of a and b, then there is γ [c] p+q that is the output of the merging of f and g. Proof. Let n = p + q and ranks(a, b) = (r 1,..., r n ). Then ranks(f, g) = ranks(a, b) = (n + 1 r 1,..., n + 1 r n ). (a) Let ranks(a) = (s 1,..., s p ), then ranks(a) = (p + 1 s 1,..., p + 1 s p ). For 1 i < j p, (p + 1 s i < p + 1 s j ) (s i > s j ) (a i > a j ) (r i > r j ) (n + 1 r i < n + 1 r j ) (f i < f j ). Therefore, ranks(f ) = (p + 1 s 1,..., p + 1 s p ) = ranks(a), i.e., f [a] p. In a similar way we can prove that g [b] q. (b) Consider a merging of a and b with exactly ϵ erroneous comparisons and exactly δ ϵ non-erroneous comparisons. Consider comparison i, where 1 i δ. Assume that a ji is compared to b ki for some j i {1,..., p} and k i {1,..., q}. Note that i = j i + k i 1. Then, (a ji < b ki ) (r ji < r p+ki ) (n + 1 r ji > n + 1 r p+ki ) (f ji > g ki ). We construct the merging of f and g (and the output γ ) inductively: without loss of generality, assume that a 1 < b 1 ; then f 1 > g 1. If an error occurs in the first comparison, then c 1 = b 1, and we assume that f 1 is compared to g 1 and no error occurs. In such a case, γ 1 = g 1. If no error occurs in the first comparison, then c 1 = a 1, and we assume that f 1 is compared to g 1 and an error occurs. In such a case, γ 1 = f 1. Let i and assume that γ 1,..., γ i 1 have been constructed as claimed in part (b) of the lemma. More precisely, assume that, for 1 v i 1, if c v = a j v, then γ v = f j v, and if c v = b k v, then γ v = g k v. Without loss of generality, assume that a ji < b ki ; then f ji > g ki. If an error occurs in comparison i, then c i = b ki, and we assume that f ji is compared to g ki and no error occurs. In such a case, γ i = g ki. If no error occurs in comparison i, then c i = a ji, and we assume that f ji is compared to g ki and an error occurs. In such a case, γ i = f ji. If c δ = a j δ then a jδ = a p and γ δ = f j δ = f p ; in such a case k δ q, c δ+s = b k δ+s 1 and γ δ+s = g k δ+s 1 for s = 1,,..., q + 1 k δ. If c δ = b k δ then b kδ = b q and γ δ = g k δ = g q ; in such a case, j δ p, c δ+s = a j δ+s 1 and γ δ+s = f j δ+s 1 for s = 1,,..., p + 1 j δ. It is clear from the above construction that c i = a ν if and only if γ i = f ν, and c i = b µ if and only if γ i = g µ. In the first case, the rank of c i in c is r ν and the rank of γ i in γ is n + 1 r ν. In the second case, the rank of c i in c is r p+µ and the rank of γ i in γ is n + 1 r p+µ. Therefore, γ [c] n. This completes the proof of the lemma. Recall that permutation functions were defined in Eq. () in Section 3. Lemma 4.4. Let n N \ {0} and σ : A n A n be a permutation function. Then σ (d) = σ (d) for all d A n. Proof. By the definition of a permutation function, there exists a permutation β of the numbers 1,,..., n such that σ (a) = a n β for all a A n. Let d r = (d (n), d (n 1),..., d (), d (1) ) be the list d in reverse sorted order. Note that σ (d) is a permutation of d, so d r is also the reverse sorted list of σ (d) as well. Then, for d A n, σ (d) = σ (d r n d) = (d r n d) n β = d r n (d n β) = d r n σ (d) = σ (d). This completes the proof of the lemma. We now describe how to define the complement, M, of an execution M of recursive merge sort that operates on a list d of length n. The complement of M operates on the complement, d, of d; it is such that E(M) + E(M) = C(M) = C(M), and the output γ of the application of M on d is the complement of the output c of the application of M on d, i.e., out(m, d) = c = out(m, d) = γ. Let σ M : A n A n be the permutation function associated with M according to Lemma 3.. We will define M recursively, prove that it satisfies the two equalities above, and show that its permutation function is σ M = σ M.

8 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) When n = 1 and d A 1, then ME 1 (d) contains only one execution M of recursive merge sort that does nothing on d. In such a case, d = d, and we define M = M. Obviously, E(M) + E(M) = = C(M) = C(M) = 0 and out(m, d) = d = out(m, d). Obviously, the permutation function for M = M is the identity function on A 1. Given n, assume that for each integer m with 1 m < n, each f A m, and each M 0 ME m (f ), we have defined the complement, M 0, of M 0 so that M 0 ME m (f ), where f A m is the complement of f. We assume that E(M 0 )+E(M 0 ) = C(M 0 ) = C(M 0 ) and out(m 0, f ) = out(m 0, f ). We also assume that M 0 and M 0 have the same permutation functions. Let d A n and M ME n (d) be given. Execution M ME n (d) breaks list d A n into two lists: d 11 = (d 1,..., d s ) of length s = n/ and d 1 = (d s+1,..., d n ) of length n s = n/. In addition, execution M is such that, each of the two sublists, d 11 and d 1, is acted upon by some executions M 11 ME s (d 11 ) and M 1 ME n s (d 1 ). These executions are sub-executions of M, and the corresponding outputs c 11 = out(m 11, d 11 ) and c 1 = out(m 1, d 1 ) will be merged into the final output list c = out(m, d) according to M. By assumption, the complements M 11 and M 1 of M 11 and M 1, respectively, can be defined so that M 11 ME s (d 11 ) and M 1 ME n s (d 1 ), where d 11 A s and d 1 A n s are the complements of d 11 and d 1, respectively, such that E(M 11 ) + E(M 11 ) = C(M 11 ) = C(M 11 ) and E(M 1 ) + E(M 1 ) = C(M 1 ) = C(M 1 ); and such that c 11 = out(m 11, d 11 ) and c 1 = out(m 1, d 1 ). Also, by Lemma 3. there are unique permutation functions σ 1 : A s A s and σ : A n s A n s such that σ 1 (d 11 ) = c 11 and σ (d 1 ) = c 1. By the inductive hypothesis, M 11 and M 11 have the same permutation functions, and so do M 1 and M 1. Thus, σ 1 (d 11 ) = c 11 and σ (d 1 ) = c 1. (This also follows from Lemma 4.4.) Let α = d = (α 1,..., α n ) A n, α 1 = (α 1,..., α s ) A s and α = (α s+1,..., α n ) A n s. Since d = (d 11, d 1 ), by Lemma 4., we have ranks(d 11 ) = ranks(α 1 ) and ranks(d 1 ) = ranks(α ), i.e., α 1 [d 11 ] s and α [d 1 ] n s. Therefore, M 11 ME s (α 1 ) and M 1 ME n s (α ). Also and γ 11 := out(m 11, α 1 ) [out(m 11, d 11 )] s = [c 11 ] s (6) γ 1 := out(m 1, α ) [out(m 1, d 1 )] n s = [c 1 ] n s. (7) It follows from (6), (7) and Lemma 3.1(b) that σ 1 (α 1 ) = γ 11 and σ (α ) = γ 1. Let β 1 be a permutation of the numbers 1,..., s and β be a permutation of the numbers 1,..., n s such that σ 1 (f ) = f s β 1 for f A s and σ (g) = g n s β for g A n s. Let d r = (d (n), d (n 1),..., d (1) ) be the reverse sorted order for d. Since (c 11, c 1 ) is a permutation of d, the reverse sorted order for (c 11, c 1 ) is also d r. Then (c 11, c 1 ) = d r n (σ 1 (d 11 ), σ (d 1 )) = d r n (d 11 s β 1, d 1 n s β ). It follows from Lemma 3.1(a) that (c 11, c 1 ) = d r n ((d 11, d 1 ) n (β 1, β + s)) = (d r n d) n (β 1, β + s) = d n (β 1, β + s). Since d = α = (α 1, α ), it follows again from Lemma 3.1(a) that Therefore, (c 11, c 1 ) = (α 1, α ) n (β 1, β + s) = (α 1 s β 1, α n s β ) = (σ 1 (α 1 ), σ (α )). (c 11, c 1 ) = (γ 11, γ 1 ). (8) We define the execution M as follows: we assume first that it breaks d = α into α 1 and α. We assume that α 1 is acted upon by M 11 and α is acted upon by M 1. We assume that the corresponding outputs γ 11 and γ 1 are merged into γ A n so that a comparison between γ 11 and γ 1 is erroneous if and only if the corresponding comparison between c 11 and c 1 is not erroneous. This is possible because of Eq. (8) and Lemma 4.3(b). If δ 1 is the number of comparisons in merging c 11 and c 1, δ is the number of comparisons in merging γ 11 and γ 1, ϵ 1 is the number of errors in merging c 11 and c 1, and ϵ is the number of errors in merging γ 11 and γ 1, then (by Lemma 4.3(b)) ϵ 1 + ϵ = δ 1 = δ and γ [c] n = [out(m, d)] n. It follows from the description of M and the definition of M that C(M) = C(M 11 ) + C(M 1 ) + δ = C(M 11 ) + C(M 1 ) + δ 1 = C(M)

9 1406 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) and E(M) + E(M) = E(M 11 ) + E(M 1 ) + ϵ 1 + E(M 11 ) + E(M 1 ) + ϵ = C(M 11 ) + C(M 1 ) + δ 1 = C(M). By the definition of M, γ = out(m, d), and therefore out(m, d) [out(m, d)] n. The sequence γ 11 is a permutation of α 1 and the sequence γ 1 is a permutation of α. Merging γ 11 and γ 1 produces γ = out(m, d), which is a permutation of α = d = (α 1, α ). Since d is a permutation of d, we have that out(m, d) is also a permutation of d. Since also ranks(out(m, d)) = ranks(out(m, d)), we conclude that out(m, d) = out(m, d). If σ M : A n A n is the permutation function associated with M (according to Lemma 3.), then it follows from Lemma 4.4 that σ M (d) = σ M (d) = c = out(m, d). By the uniqueness of permutation functions associated with executions of recursive merge sort (see Lemma 3.), we conclude that σ M = σ M. This concludes the inductive step and our claims (about the existence and properties of M) have been proven. 5. Number of runs Given integers p, q 1 and sequences a A p and b A q with {a 1,..., a p } {b 1,..., b q } =, and an integer e 0, let M(a, b, e) be the set of all sequences c A p+q that arise from merging a and b with exactly e errors in comparisons. For example, if a = (3, 4) and b = (1, ), then M(a, b, e = 1) = {(3, 1,, 4), (1, 3,, 4)}. A slightly weaker version of the following lemma was proven in [, Observation 1], but our proof is different. Lemma 5.1. Given integers p, q 1, sequences a A p and b A q with {a 1,..., a p } {b 1,..., b q } =, and an integer e with 0 e p + q 1, assume that M(a, b, e). Then for any c M(a, b, e), R(c) R(a) + R(b) + e 1. Proof. If c = (c 1,..., c p+q ), then R(c) 1 equals the number of pairs (c i, c i+1 ) with 1 i p + q 1 and c i > c i+1. These pairs fall into three mutually exclusive categories: (i) those pairs with c i = a j > c i+1 = a j+1 for some integer j with 1 j p 1; (ii) those pairs with c i = b k > c i+1 = b k+1 for some integer k with 1 k q 1, and (iii) those pairs with c i = a j > c i+1 = b k or c i = b k > c i+1 = a j for some integers j and k with 1 j p and 1 k q. The last type of pairs are the result of errors in comparisons. The first two types of pairs may or may not be the results of errors in comparisons. Then R(c) 1 (R(a) 1) + (R(b) 1) + e, from which (9) follows. The following theorem is the main result of the section. It gives exact values for the maximum and the minimum number of runs of the output sequence of recursive merge sort when the number of erroneous comparisons is small. (We have actually proven that mruns(n, e) = even when n/ + 1 e n 1, but our proof is so long that we decided not to include it in this paper.) Theorem 5.. Let n and e be integers such that n 1 and 0 e n/. Then Mruns(n, e) = e + 1. In addition, mruns(n, e = 0) = 1 and mruns(n, e) = for 1 e n/. Proof. We first prove by induction on n that for all integers e with 0 e W(n), Mruns(n, e) e + 1. (This inequality was also proven in a similar way by Ravikumar [, Observation 3], but for completeness we provide a proof that illustrates the notation and methods of our paper.) For n = 1, we have 0 e W(1) = 0, and A(n = 1, e = 0) contains only one pair (d, M) with d A 1, M ME 1 (d) and E(M) = 0 = e. In such a case, R(d, M) = 1 and Mruns(n = 1, e = 0) = 1 = Let n, and assume that for all integers m and e with 1 m < n and 0 e W(m) we have Mruns(m, e) e+1. Let ϵ be an integer such that 0 ϵ W(n). Let d A n and M ME n (d) be such that E(M) = ϵ. Suppose execution M breaks list d = (d 1,..., d n ) into two lists: d 11 = (d 1,..., d s ) of length s = n/ and d 1 = (d s+1,..., d n ) of length n s = n/. In addition, execution M is such that, each of the two sublists, d 11 and d 1, is acted upon by some executions M 11 ME s (d 11 ) and M 1 ME n s (d 1 ) such that E(M 11 ) = ϵ 1 and E(M 1 ) = ϵ (where 0 ϵ 1 W(s) and 0 ϵ W(n s)). The corresponding outputs c 11 and c 1 will be merged into the final output list c according to M, say with exactly ϵ 3 errors in comparisons. Obviously, ϵ 1 + ϵ + ϵ 3 = ϵ. By the induction hypothesis, R(d 11, M 11 ) Mruns(s, ϵ 1 ) ϵ (1) (9) (10) (11)

10 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) and R(d 1, M 1 ) Mruns(n s, ϵ ) ϵ + 1. (13) By Lemma 5.1, R(d, M) R(d 11, M 11 ) + R(d 1, M 1 ) + ϵ 3 1. (14) It follows from (1) (14) that R(d, M) ϵ ϵ ϵ 3 1 = ϵ + 1. Since (d, M) is an arbitrary member of A(n, ϵ), it follows that Mruns(n, ϵ) ϵ + 1 and the inductive step is complete. To show equality in (10), let s = n/, n s = n/, and ˆd = (1,,..., s, s + 1, s +,..., n). Assume that ˆM ME n (ˆd) breaks ˆd into ˆd11 = (1,,..., s) A s and ˆd1 = (s+1, s+,..., n), and applies ˆM11 ME s (ˆd11 ) on ˆd11 and ˆM1 ME n s (ˆd11 ) on ˆd1 such that E( ˆM11 ) = 0 = E( ˆM1 ). (This is obviously possible.) We also assume that the outputs ĉ 11 = ˆd11 and ĉ 1 = ˆd1 are merged so that there are errors only in comparisons 1, 3,..., e 1. This is possible since e s n s. It is then easy to see that the output sequence of the application of ˆM on ˆd will be ĉ = (s + 1, 1, s +,,..., s + e, e, e + 1,..., s, s + e + 1,..., n). Since E( ˆM) = e and R(ˆd, ˆM) = R(ĉ) = e + 1, we have shown that the equality holds in (10). Obviously mruns(n, e = 0) = 1 and mruns(n, e) when 1 e n 1 when there is at least one error in comparison, then there is at least one inversion in the final output. To show equality for the case 1 e s = n/, suppose that we have ˆd as given in (15) and we apply execution ˆM on ˆd as described above, but in the merging of ĉ 11 = ˆd11 and ĉ 1 = ˆd1 the e errors occur only in comparisons 1,,..., e. This is possible because e s n s. The output sequence is c = (s + 1,..., s + e, 1,,..., s, s + e + 1,..., n). (16) (If n is even and e = n/, then the previous output becomes c = (s + 1,..., s + e, 1,,..., s).) We have R(c) =, which implies mruns(n, e) =. The next theorem gives the minimum and the maximum number of runs for the output sequence of recursive merge sort when the number of erroneous comparisons is very large (compared to the length of the input sequence). First, we need to define the sequence (Λ(n) : n = 1,,...) by n n n Λ(n) = Λ + Λ +, n, (17) and Λ(1) = 0. Lemma A.1 in the Appendix gives an explicit formula for Λ(n) in terms of the binary expansion of n, but the formula is not that useful for the results of this paper. Theorem 5.3. Let n and e be integers such that n 1 and 0 e W(n). Then Mruns(n, e) = n = mruns(n, e) if and only if Λ(n) e W(n). Proof. (i) Assume that Λ(n) e W(n). By Lemma A.6 in the Appendix, there are d A n and M ME n (d) such that out(m, d) = (1,,..., n), E(M) = 0 and C(M) = e. Using the theory of complements from Section 4, we have d A n and M ME n (d) with E(M) + E(M) = C(M) = C(M) and out(m, d) = out(m, d) = (n, n 1,..., 1). It follows that E(M) = e and R(M, d) = n, which imply Mruns(n, e) = n. (ii) Assume that Mruns(n, e) = n. Choose d 0 A n and M 0 ME n (d) such that R(d 0, M 0 ) = n and E(M 0 ) = e. It follows that out(m 0, d 0 ) = (n, n 1,..., 1). Using complements we obtain out(m 0, d 0 ) = (1,,..., n) (and thus E(M 0 ) = 0) and E(M 0 ) + E(M 0 ) = C(M 0 ) = C(M 0 ). It follows that C(M 0 ) = e. It follows from the definition of C(n) (see Eq. (33) in the Appendix) that e C(n). By Lemma A.5 in the Appendix, Λ(n) e W(n). Corollary 5.4. Let n be an integer with n. If e = Λ(n) 1, then Mruns(n, e) = n 1. Proof. By Theorem 5.3, Mruns(n, e) n 1 for e = Λ(n) 1. Let d = (, 1, 3,..., n) and let M ME n (d) be the execution of recursive merge sort that errs only when comparing and 1. Then E(M) = 1, C(M) = Λ(n), and out(m, d) = d. Thus, R(d, M) =. Using the complements of d and M (see Section 4) we conclude that out(m, d) = d = (n 1, n, n,..., 1), C(M) = C(M) = Λ(n), and E(M) = C(M) E(M) = Λ(n) 1. Since R(d, M) = n 1, we conclude that Mruns(n, e) = n Smallest number of removals In the section, for some cases of n and e, we give upper and lower bounds for the maximum (and exact values for the minimum) of the smallest number of integers that need to be removed in order to sort the output list of an execution of recursive merge sort when some of the comparisons are in error. (15)

11 1408 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) Parts (b) and (c) of Theorem 6.1 imply that Mrem(n, 1) n/4 for n. In fact, a slight modification of the proofs of Lemmas 4 6 in [14] shows that we actually have equality 1 : Mrem(n, 1) = n/4 for n. For part (d) of the following theorem, we need to define the following double sequence: and Ξ(n, 1) = n/4 for n 0, Ξ(n, e) = min ( n/ + 1, n/4 + Ξ( n/, e 1)) for n 0 and e. Theorem 6.1. Let n and e be integers such that n 1 and 0 e W(n). (a) We have Mrem(n, 0) = 0 = mrem(n, 0). (b) We have Mrem(, 1) = 1 = Mrem(3, 1) and Mrem(3, ) = Mrem(3, 3) =. (c) If n 4 and 1 e n/, then n ne + e 1 Mrem(n, e). 4 e + 1 (d) If n 6 and 1 e log (n/3), then n n ne Ξ(n, e) Mrem(n, e). e+1 e + 1 (e) If 1 e n/, then mrem(n, e) = 1. (f) We have Mrem(n, e) = n 1 = mrem(n, e) if and only if Λ(n) e W(n). (g) If n, then Mrem(n, Λ(n) 1) = n. Proof. (a) The proof of this part is trivial. (b) Since Λ() = 1 = W(), Λ(3) = and W(3) = 3, the equalities in this part follow from parts (f) and (g) of this theorem. (c) The right inequality follows from the inequality n(r(a) 1) RM(a), R(a) which is valid for n and a A n (see Lemma.5 in [13]) and Theorem 5. in this paper. To prove the left inequality, we let n 4 and 1 e n/4 and consider four cases. Case (c)(i). Assume that n = 4ν where ν 1. In this case, we assume that 1 e n/ = ν. Let d 1 = (ν + 1,..., ν), d = (ν + 1,..., 3ν), d 3 = (1,,..., ν), d 4 = (3ν + 1,..., 4ν), d 11 = (d 1, d ), d 1 = (d 3, d 4 ), and d = (d 11, d 1 ). Obviously, there are unique executions M 1 ME ν (d 11 ), M ME ν (d ), M 3 ME ν (d 3 ) and M 4 ME ν (d 4 ) such that E(M 1 ) = E(M ) = E(M 3 ) = E(M 4 ) = 0. Assume that M 11 ME ν (d 11 ) breaks d 11 into d 1 and d, applies M 1 on d 1 with output d 1, applies M on d with output d, and merges d 1 and d so that only the first e 1 comparisons are erroneous. Then c 11 = out(m 11, d 11 ) = (ν + 1,..., ν + e 1, ν + 1, ν +,..., ν, ν + e,..., 3ν). Similarly, assume that M 1 ME ν (d 1 ) breaks d 1 into d 3 and d 4, applies M 3 on d 3 with output d 3, applies M 4 on d 4 with output d 4, and merges d 3 and d 4 so that only the first comparison is erroneous. Then, c 1 = out(m 1, d 1 ) = (3ν + 1, 1,,..., ν, 3ν +, 3ν + 3,..., 4ν). Finally, assume that M ME n (d) breaks d into d 11 and d 1, applies M 11 on d 11 with output c 11, applies M 1 on d 1 with output c 1, and merges c 11 and c 1 with no errors in comparisons. Then E(M) = (e 1) + 1 = e and c = out(m, d) = (ν + 1,..., ν + e 1, ν + 1, ν +,..., ν, ν + e,..., 3ν, 3ν + 1, 1,,..., ν, 3ν +,..., 4ν). (18) (If e = 1, then c = (ν + 1, ν +,..., ν, ν + 1,..., 3ν, 3ν + 1, 1,,..., ν, 3ν +,..., 4ν). In particular, if e = 1 and ν = 1, then c = (, 3, 4, 1).) We observe that RM(d, M) = ν + e 1 = n/4 + e 1. Case (c)(ii). Assume that n = 4ν + 1 where ν 1. In this case, we assume that 1 e n/ = ν. Use an example similar to the one in case (c)(i), except d 1 = (ν +,..., ν + 1), d = (ν +,..., 3ν + 1), d 3 = (3ν +,..., 4ν + 1), 1 For simplicity, in Lemma 6 of their paper, Islam and Lakshmanan [14] assume that n is a multiple of 4.

12 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) and d 4 = (1,,..., ν + 1). In such a case, c = out(m, d) = (ν +,..., ν + e, ν +, ν + 3,..., ν + 1, ν + e + 1,..., 3ν + 1, 3ν +, 1,,..., ν + 1, 3ν + 3,..., 4ν + 1). (If e = 1, then c = (ν +, ν + 3,..., ν + 1, ν +,..., 3ν +, 1,,..., ν + 1, 3ν + 3,..., 4ν + 1). In particular, if e = 1 and ν = 1, then c = (3, 4, 5, 1, ).) Then RM(d, M) = (ν + 1) + e 1 = n/4 + e 1. Case (c)(iii). Assume that n = 4ν + where ν 1. In this case, we assume that 1 e n/ = ν + 1. Let d 1 = (ν +,..., ν + 1), d = (ν +,..., 3ν + ), d 3 = (3ν + 3,..., 4ν + ), and d 4 = (1,,..., ν + 1). Define d 11, d 1, M 1, M, M 3, M 4, M 11, M 1, and M similarly to the ones in case (c)(i). Then c = out(m, d) = (ν +,..., ν + e, ν +, ν + 3,..., ν + 1, ν + e + 1,..., 3ν +, 3ν + 3, 1,,..., ν + 1, 3ν + 4,..., 4ν + ). (If e = 1, then c = (ν +, ν + 3,..., ν + 1, ν +,..., 3ν + 3, 1,,..., ν + 1, 3ν + 4,..., 4ν + ). In particular, if e = 1 and ν = 1, then c = (3, 4, 5, 6, 1, ).) Then RM(d, M) = (ν + 1) + e 1 = n/4 + e 1. Case (c)(iv). Assume that n = 4ν +3 where ν 1. In this case, we assume that 1 e n/ = ν +1. Use an example similar to the one in case (c)(i), except d 1 = (ν +,..., ν + 1), d = (ν +,..., 3ν + ), d 3 = (1,,..., ν + 1) and d 4 = (3ν + 3,..., 4ν + 3). Then c = out(m, d) = (ν +,..., ν + e, ν +, ν + 3,..., ν + 1, ν + e + 1,..., 3ν +, 3ν + 3, 1,,..., ν + 1, 3ν + 4,..., 4ν + 3). (If e = 1, then c = (ν +, ν + 3,..., ν + 1, ν +,..., 3ν + 3, 1,,..., ν + 1, 3ν + 4,..., 4ν + 3). In particular, if e = 1 and ν = 1, then c = (3, 4, 5, 6, 1,, 7).) Then RM(d, M) = (ν + 1) + e 1 = n/4 + e 1. (d) The proof of the right inequality is the same as in part (c). To prove the left inequality involving Ξ(n, e), we show by induction on e 1 that for each integer n with e log (n/3) and n 6, there are d A n and M ME n (d) such that E(M) = e and RM(d, M) Ξ(n, e). For e = 1 the inequality follows from the left inequality in part (c) of this theorem. Let e and assume for each integer ẽ < e and integer m 6 with 1 ẽ log (m/3) there are d Am and M ME m ( d) such that E( M) = ẽ and RM( d, M) Ξ(m, ẽ). Let n 6 be such that e log (n/3). Let s = n/. Since e, we have s 6. We have 1 e 1 log (n/3) 1 = log (n/6) = log (s/3). By the inductive hypothesis, there are d 11 A s and M 11 ME s (d 11 ) such that E(M 11 ) = e 1 and RM(d 11, M 11 ) Ξ(s, e 1). Without loss of generality, we may assume that d 11 is a permutation of the integers (ν + 1,..., 3ν) if n = 4ν, (ν +,..., 3ν + 1) if n = 4ν + 1, (ν +,..., 3ν + ) if n = 4ν +,. (19) (ν +,..., 3ν + ) if n = 4ν + 3 We also define d 3, d 4, M 3, and M 4 as in cases (i) (iv) in the proof of part (c) of this theorem (with E(M 3 ) = 0 = E(M 4 )). Let d 1 = (d 3, d 4 ) A n s, and define M 1 ME n s (d 1 ) as follows: it breaks d 1 into d 3 amd d 4, applies M 3 on d 3 with output d 3, applies M 4 on d 4 with output d 4, and merges d 3 with d 4 with an error only on the first comparison. Then (3ν + 1, 1,..., ν, 3ν +,..., 4ν) if n = 4ν, c 1 = out(m 1, d 1 (3ν +, 1,..., ν + 1, 3ν + 3,..., 4ν + 1) if n = 4ν + 1, ) = (3ν + 3, 1,..., ν + 1, 3ν + 4,..., 4ν + ) if n = 4ν +,. (3ν + 3, 1,..., ν + 1, 3ν + 4,..., 4ν + 3) if n = 4ν + 3 Let d = (d 11, d 1 ) and define M ME n (d) as follows: It breaks d into d 11 and d 1, applies M 11 on d 11 and gives output c 11, applies M 1 on d 1 and obtains output c 1, and merges c 11 and c 1 with no errors in comparisons, and gives output c = out(m, d) = (c 11, c 1 ) (because the first element of c 1 is greater than each element of c 11 ). Note that E(M) = e. Now RM(d, M) is the minimum of the following two numbers: (i) n/ + 1, which is obtained by removing c 11 and the first element of c 1 from c; (ii) RM(d 11, M 11 ) + n 4, which is obtained by removing RM(d 11, M 11 ) elements from c 11 so that c 11 is left sorted, and removing 1,,..., n/4 from c 1. It follows that n RM(d, M) = min n/ + 1, RM(d 11, M 11 ) + 4 n min n/ + 1, Ξ( n/, e 1) + = Ξ(n, e), 4 and the induction step is complete.

13 1410 P. Hadjicostas, K.B. Lakshmanan / Discrete Applied Mathematics 159 (011) To prove the inequality Ξ(n, e) n/ n/ e+1 for n 0 and e 1, we use induction on e. For e = 1 we have Ξ(n, 1) = n/4 n/ n/ 1+1 because n n = n n 4 4. Let e and assume that the inequality is true for all integers ẽ with 1 ẽ < e and all integers n 0. Fix an integer n 0. Then n n n n n n/ n/ Ξ(n, e) = min + 1, + Ξ, e 1 min + 1, e To finish the induction, it is sufficient to prove that n n/ n/ n n +. 4 e e+1 The latter inequality follows if we prove that n n/ n + 4 and n e+1 n/ e. If n = ν (where ν 0), inequality (0) holds as an equality: n n/ ν ν n + = + = ν =. 4 If n = ν + 1 (where ν 0), we have n n/ ν + = ν + 4 Inequality (1) follows from n n/ n/ =. e+1 e e ν ν + = ν = This completes the induction, and the proof of part (d) of the theorem is complete. (e) Obviously mrem(n, e) 1 when e 1 when there is at least one error in comparison, then there is at least one inversion in the final output. To prove equality, let s = n/ and d = (1, n/ +,..., n,, 3,..., n/ + 1) and assume that M ME n (d) breaks d into d 11 = (1, n/ +,..., n) and d 1 = (, 3,..., n/ + 1), applies M 11 ME s (d 11 ) on d 11 and M 1 ME n s (d 1 ) on d 1 such that E(M 11 ) = 0 = E(M 1 ). (This is obviously possible.) Then assume that the outputs c 11 = d 11 and c 1 = d 1 are merged so that errors occur only in comparisons 1,,..., e. Then the output is c = (, 3,..., e + 1, 1, e +,..., n) and RM(d, M) = 1. (f) This part follows from Theorem 5.3 and the fact that for a A n we have RM(a) = n 1 if and only if a = (n, n 1,..., 1) if and only if R(a) = n. (g) By part (f) of this theorem, Mrem(n, e) n for e = Λ(n) 1. Using M and d = (, 1, 3,..., n) as defined in the example in the proof of Corollary 5.4, we obtain out(m, d) = (n 1, n, n, n 3,..., 1), E(M) = Λ(n) 1, and RM(d, M) = n. Hence Mrem(n, e) = n for e = Λ(n) Number of inversions In the section, for some values of n and e, we give upper and lower bounds for the maximum (and exact values for the minimum) number of inversions in the output list of an execution of recursive merge sort when some of the comparisons are in error. Before proving the main theorem of the section, we need the following lemma (which is used in the proof of part (d) in Theorem 7.). n. (0) (1)

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14 Divide and Conquer Algorithms CSE 101: Design and Analysis of Algorithms Lecture 14 CSE 101: Design and analysis of algorithms Divide and conquer algorithms Reading: Sections 2.3 and 2.4 Homework 6 will

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali February 19, 2013 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali March 17, 2014 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine solutions

More information

Divide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014

Divide&Conquer: MergeSort. Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 Divide&Conquer: MergeSort Algorithmic Thinking Luay Nakhleh Department of Computer Science Rice University Spring 2014 1 Divide-and-Conquer Algorithms Divide-and-conquer algorithms work according to the

More information

Lecture 4. Quicksort

Lecture 4. Quicksort Lecture 4. Quicksort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018 Networking

More information

CHAPTER 8: EXPLORING R

CHAPTER 8: EXPLORING R CHAPTER 8: EXPLORING R LECTURE NOTES FOR MATH 378 (CSUSM, SPRING 2009). WAYNE AITKEN In the previous chapter we discussed the need for a complete ordered field. The field Q is not complete, so we constructed

More information

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

More information

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 CS17 Integrated Introduction to Computer Science Klein Contents Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 1 Tree definitions 1 2 Analysis of mergesort using a binary tree 1 3 Analysis of

More information

Theoretical Computer Science

Theoretical Computer Science Theoretical Computer Science 411 (2010) 3224 3234 Contents lists available at ScienceDirect Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs N-player partizan games Alessandro

More information

FIBONACCI NUMBERS AND DECIMATION OF BINARY SEQUENCES

FIBONACCI NUMBERS AND DECIMATION OF BINARY SEQUENCES FIBONACCI NUMBERS AND DECIMATION OF BINARY SEQUENCES Jovan Dj. Golić Security Innovation, Telecom Italia Via Reiss Romoli 274, 10148 Turin, Italy (Submitted August 2004-Final Revision April 200) ABSTRACT

More information

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction Math 4 Summer 01 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 MA008 p.1/37 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/37 Exercise 1 (from LN 2) Asymptotic Notation When constants appear in exponents

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

More information

COL106: Data Structures and Algorithms (IIT Delhi, Semester-II )

COL106: Data Structures and Algorithms (IIT Delhi, Semester-II ) 1 Solve the following recurrence relations giving a Θ bound for each of the cases 1 : (a) T (n) = 2T (n/3) + 1; T (1) = 1 (Assume n is a power of 3) (b) T (n) = 5T (n/4) + n; T (1) = 1 (Assume n is a power

More information

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d CS161, Lecture 4 Median, Selection, and the Substitution Method Scribe: Albert Chen and Juliana Cook (2015), Sam Kim (2016), Gregory Valiant (2017) Date: January 23, 2017 1 Introduction Last lecture, we

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

Discrete Applied Mathematics. Tighter bounds of the First Fit algorithm for the bin-packing problem

Discrete Applied Mathematics. Tighter bounds of the First Fit algorithm for the bin-packing problem Discrete Applied Mathematics 158 (010) 1668 1675 Contents lists available at ScienceDirect Discrete Applied Mathematics journal homepage: www.elsevier.com/locate/dam Tighter bounds of the First Fit algorithm

More information

arxiv: v2 [cs.ds] 17 Sep 2017

arxiv: v2 [cs.ds] 17 Sep 2017 Two-Dimensional Indirect Binary Search for the Positive One-In-Three Satisfiability Problem arxiv:1708.08377v [cs.ds] 17 Sep 017 Shunichi Matsubara Aoyama Gakuin University, 5-10-1, Fuchinobe, Chuo-ku,

More information

Fundamental Algorithms

Fundamental Algorithms Chapter 2: Sorting, Winter 2018/19 1 Fundamental Algorithms Chapter 2: Sorting Jan Křetínský Winter 2018/19 Chapter 2: Sorting, Winter 2018/19 2 Part I Simple Sorts Chapter 2: Sorting, Winter 2018/19 3

More information

Fundamental Algorithms

Fundamental Algorithms Fundamental Algorithms Chapter 2: Sorting Harald Räcke Winter 2015/16 Chapter 2: Sorting, Winter 2015/16 1 Part I Simple Sorts Chapter 2: Sorting, Winter 2015/16 2 The Sorting Problem Definition Sorting

More information

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers.

MATH 324 Summer 2011 Elementary Number Theory. Notes on Mathematical Induction. Recall the following axiom for the set of integers. MATH 4 Summer 011 Elementary Number Theory Notes on Mathematical Induction Principle of Mathematical Induction Recall the following axiom for the set of integers. Well-Ordering Axiom for the Integers If

More information

Parallel Recursion: Powerlists. Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin

Parallel Recursion: Powerlists. Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Parallel Recursion: Powerlists Greg Plaxton Theory in Programming Practice, Fall 2005 Department of Computer Science University of Texas at Austin Overview Definition of a powerlist Basic operations on

More information

Week 5: Quicksort, Lower bound, Greedy

Week 5: Quicksort, Lower bound, Greedy Week 5: Quicksort, Lower bound, Greedy Agenda: Quicksort: Average case Lower bound for sorting Greedy method 1 Week 5: Quicksort Recall Quicksort: The ideas: Pick one key Compare to others: partition into

More information

n n P} is a bounded subset Proof. Let A be a nonempty subset of Z, bounded above. Define the set

n n P} is a bounded subset Proof. Let A be a nonempty subset of Z, bounded above. Define the set 1 Mathematical Induction We assume that the set Z of integers are well defined, and we are familiar with the addition, subtraction, multiplication, and division. In particular, we assume the following

More information

Quick Sort Notes , Spring 2010

Quick Sort Notes , Spring 2010 Quick Sort Notes 18.310, Spring 2010 0.1 Randomized Median Finding In a previous lecture, we discussed the problem of finding the median of a list of m elements, or more generally the element of rank m.

More information

Classical Complexity and Fixed-Parameter Tractability of Simultaneous Consecutive Ones Submatrix & Editing Problems

Classical Complexity and Fixed-Parameter Tractability of Simultaneous Consecutive Ones Submatrix & Editing Problems Classical Complexity and Fixed-Parameter Tractability of Simultaneous Consecutive Ones Submatrix & Editing Problems Rani M. R, Mohith Jagalmohanan, R. Subashini Binary matrices having simultaneous consecutive

More information

Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM

Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM Sorting Chapter 11-1 - Sorting Ø We have seen the advantage of sorted data representations for a number of applications q Sparse vectors q Maps q Dictionaries Ø Here we consider the problem of how to efficiently

More information

Oblivious and Adaptive Strategies for the Majority and Plurality Problems

Oblivious and Adaptive Strategies for the Majority and Plurality Problems Oblivious and Adaptive Strategies for the Majority and Plurality Problems Fan Chung 1, Ron Graham 1, Jia Mao 1, and Andrew Yao 2 1 Department of Computer Science and Engineering, University of California,

More information

Advanced Analysis of Algorithms - Midterm (Solutions)

Advanced Analysis of Algorithms - Midterm (Solutions) Advanced Analysis of Algorithms - Midterm (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu} 1 Problems 1. Solve the following recurrence using substitution:

More information

Lecture 14: Nov. 11 & 13

Lecture 14: Nov. 11 & 13 CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting

More information

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

More information

Divide-and-conquer. Curs 2015

Divide-and-conquer. Curs 2015 Divide-and-conquer Curs 2015 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers. Known Examples: Binary

More information

The following techniques for methods of proofs are discussed in our text: - Vacuous proof - Trivial proof

The following techniques for methods of proofs are discussed in our text: - Vacuous proof - Trivial proof Ch. 1.6 Introduction to Proofs The following techniques for methods of proofs are discussed in our text - Vacuous proof - Trivial proof - Direct proof - Indirect proof (our book calls this by contraposition)

More information

Estimates for probabilities of independent events and infinite series

Estimates for probabilities of independent events and infinite series Estimates for probabilities of independent events and infinite series Jürgen Grahl and Shahar evo September 9, 06 arxiv:609.0894v [math.pr] 8 Sep 06 Abstract This paper deals with finite or infinite sequences

More information

Solvability of the halting and reachability problem for binary 2-tag systems

Solvability of the halting and reachability problem for binary 2-tag systems Fundamenta Informaticae XX (200) 37 IOS Press Solvability of the halting and reachability problem for binary 2-tag systems Liesbeth De Mol Centre for Logic and Philosophy of Science Gent University Blandijnberg

More information

CHAPTER 8 Advanced Counting Techniques

CHAPTER 8 Advanced Counting Techniques 96 Chapter 8 Advanced Counting Techniques CHAPTER 8 Advanced Counting Techniques SECTION 8. Applications of Recurrence Relations 2. a) A permutation of a set with n elements consists of a choice of a first

More information

Hierarchy among Automata on Linear Orderings

Hierarchy among Automata on Linear Orderings Hierarchy among Automata on Linear Orderings Véronique Bruyère Institut d Informatique Université de Mons-Hainaut Olivier Carton LIAFA Université Paris 7 Abstract In a preceding paper, automata and rational

More information

Data selection. Lower complexity bound for sorting

Data selection. Lower complexity bound for sorting Data selection. Lower complexity bound for sorting Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 12 1 Data selection: Quickselect 2 Lower complexity bound for sorting 3 The

More information

Discrete Applied Mathematics

Discrete Applied Mathematics Discrete Applied Mathematics 194 (015) 37 59 Contents lists available at ScienceDirect Discrete Applied Mathematics journal homepage: wwwelseviercom/locate/dam Loopy, Hankel, and combinatorially skew-hankel

More information

COL 730: Parallel Programming

COL 730: Parallel Programming COL 730: Parallel Programming PARALLEL SORTING Bitonic Merge and Sort Bitonic sequence: {a 0, a 1,, a n-1 }: A sequence with a monotonically increasing part and a monotonically decreasing part For some

More information

Homework 4, 5, 6 Solutions. > 0, and so a n 0 = n + 1 n = ( n+1 n)( n+1+ n) 1 if n is odd 1/n if n is even diverges.

Homework 4, 5, 6 Solutions. > 0, and so a n 0 = n + 1 n = ( n+1 n)( n+1+ n) 1 if n is odd 1/n if n is even diverges. 2..2(a) lim a n = 0. Homework 4, 5, 6 Solutions Proof. Let ɛ > 0. Then for n n = 2+ 2ɛ we have 2n 3 4+ ɛ 3 > ɛ > 0, so 0 < 2n 3 < ɛ, and thus a n 0 = 2n 3 < ɛ. 2..2(g) lim ( n + n) = 0. Proof. Let ɛ >

More information

Lecture 4: Two-point Sampling, Coupon Collector s problem

Lecture 4: Two-point Sampling, Coupon Collector s problem Randomized Algorithms Lecture 4: Two-point Sampling, Coupon Collector s problem Sotiris Nikoletseas Associate Professor CEID - ETY Course 2013-2014 Sotiris Nikoletseas, Associate Professor Randomized Algorithms

More information

CS 2110: INDUCTION DISCUSSION TOPICS

CS 2110: INDUCTION DISCUSSION TOPICS CS 110: INDUCTION DISCUSSION TOPICS The following ideas are suggestions for how to handle your discussion classes. You can do as much or as little of this as you want. You can either present at the board,

More information

Analysis of Algorithms CMPSC 565

Analysis of Algorithms CMPSC 565 Analysis of Algorithms CMPSC 565 LECTURES 38-39 Randomized Algorithms II Quickselect Quicksort Running time Adam Smith L1.1 Types of randomized analysis Average-case analysis : Assume data is distributed

More information

Scheduling jobs with agreeable processing times and due dates on a single batch processing machine

Scheduling jobs with agreeable processing times and due dates on a single batch processing machine Theoretical Computer Science 374 007 159 169 www.elsevier.com/locate/tcs Scheduling jobs with agreeable processing times and due dates on a single batch processing machine L.L. Liu, C.T. Ng, T.C.E. Cheng

More information

Advanced Counting Techniques. Chapter 8

Advanced Counting Techniques. Chapter 8 Advanced Counting Techniques Chapter 8 Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence Relations Nonhomogeneous Recurrence Relations Divide-and-Conquer

More information

The best expert versus the smartest algorithm

The best expert versus the smartest algorithm Theoretical Computer Science 34 004 361 380 www.elsevier.com/locate/tcs The best expert versus the smartest algorithm Peter Chen a, Guoli Ding b; a Department of Computer Science, Louisiana State University,

More information

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture 1: Asymptotics, Recurrences, Elementary Sorting Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running

More information

Divide and conquer. Philip II of Macedon

Divide and conquer. Philip II of Macedon Divide and conquer Philip II of Macedon Divide and conquer 1) Divide your problem into subproblems 2) Solve the subproblems recursively, that is, run the same algorithm on the subproblems (when the subproblems

More information

MATH 556: PROBABILITY PRIMER

MATH 556: PROBABILITY PRIMER MATH 6: PROBABILITY PRIMER 1 DEFINITIONS, TERMINOLOGY, NOTATION 1.1 EVENTS AND THE SAMPLE SPACE Definition 1.1 An experiment is a one-off or repeatable process or procedure for which (a there is a well-defined

More information

On binary reflected Gray codes and functions

On binary reflected Gray codes and functions Discrete Mathematics 308 (008) 1690 1700 www.elsevier.com/locate/disc On binary reflected Gray codes and functions Martin W. Bunder, Keith P. Tognetti, Glen E. Wheeler School of Mathematics and Applied

More information

EMBEDDED PATHS AND CYCLES IN FAULTY HYPERCUBES

EMBEDDED PATHS AND CYCLES IN FAULTY HYPERCUBES EMBEDDED PATHS AND CYCLES IN FAULTY HYPERCUBES NELSON CASTAÑEDA AND IVAN S. GOTCHEV Abstract. An important task in the theory of hypercubes is to establish the maximum integer f n such that for every set

More information

Searching. Sorting. Lambdas

Searching. Sorting. Lambdas .. s Babes-Bolyai University arthur@cs.ubbcluj.ro Overview 1 2 3 Feedback for the course You can write feedback at academicinfo.ubbcluj.ro It is both important as well as anonymous Write both what you

More information

The Radicans. James B. Wilson. April 13, 2002

The Radicans. James B. Wilson. April 13, 2002 The Radicans James B. Wilson April 13, 2002 1 Radices of Integers Computational mathematics has brought awareness to the use of various bases in representing integers. The standard for most number systems

More information

Introduction to Randomized Algorithms: Quick Sort and Quick Selection

Introduction to Randomized Algorithms: Quick Sort and Quick Selection Chapter 14 Introduction to Randomized Algorithms: Quick Sort and Quick Selection CS 473: Fundamental Algorithms, Spring 2011 March 10, 2011 14.1 Introduction to Randomized Algorithms 14.2 Introduction

More information

Linear Time Selection

Linear Time Selection Linear Time Selection Given (x,y coordinates of N houses, where should you build road These lecture slides are adapted from CLRS.. Princeton University COS Theory of Algorithms Spring 0 Kevin Wayne Given

More information

ALTERNATIVE SECTION 12.2 SUPPLEMENT TO BECK AND GEOGHEGAN S ART OF PROOF

ALTERNATIVE SECTION 12.2 SUPPLEMENT TO BECK AND GEOGHEGAN S ART OF PROOF ALTERNATIVE SECTION 12.2 SUPPLEMENT TO BECK AND GEOGHEGAN S ART OF PROOF MICHAEL P. COHEN Remark. The purpose of these notes is to serve as an alternative Section 12.2 for Beck and Geoghegan s Art of Proof.

More information

Advanced Counting Techniques

Advanced Counting Techniques . All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education. Advanced Counting

More information

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015 CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015 1 Introduction The divide-and-conquer strategy is a general paradigm for algorithm design. This strategy

More information

= ϕ r cos θ. 0 cos ξ sin ξ and sin ξ cos ξ. sin ξ 0 cos ξ

= ϕ r cos θ. 0 cos ξ sin ξ and sin ξ cos ξ. sin ξ 0 cos ξ 8. The Banach-Tarski paradox May, 2012 The Banach-Tarski paradox is that a unit ball in Euclidean -space can be decomposed into finitely many parts which can then be reassembled to form two unit balls

More information

We want to show P (n) is true for all integers

We want to show P (n) is true for all integers Generalized Induction Proof: Let P (n) be the proposition 1 + 2 + 2 2 + + 2 n = 2 n+1 1. We want to show P (n) is true for all integers n 0. Generalized Induction Example: Use generalized induction to

More information

Solutions. Problem 1: Suppose a polynomial in n of degree d has the form

Solutions. Problem 1: Suppose a polynomial in n of degree d has the form Assignment 1 1. Problem 3-1 on p. 57 2. Problem 3-2 on p. 58 3. Problem 4-5 on p. 86 4. Problem 6-1 on p. 142 5. Problem 7-4 on p. 162 6. Prove correctness (including halting) of SelectionSort (use loop

More information

Sorting and Selection with Imprecise Comparisons

Sorting and Selection with Imprecise Comparisons Sorting and Selection with Imprecise Comparisons Miklós Ajtai IBM Research - Almaden ajtai@us.ibm.com Vitaly Feldman IBM Research - Almaden vitaly@post.harvad.edu Jelani Nelson Harvard University minilek@seas.harvard.edu

More information

Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort

Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort Partition n elements array A into two subarrays of n/2 elements each Sort the

More information

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort Sorting Algorithms We have already seen: Selection-sort Insertion-sort Heap-sort We will see: Bubble-sort Merge-sort Quick-sort We will show that: O(n log n) is optimal for comparison based sorting. Bubble-Sort

More information

Pattern Avoidance in Reverse Double Lists

Pattern Avoidance in Reverse Double Lists Pattern Avoidance in Reverse Double Lists Marika Diepenbroek, Monica Maus, Alex Stoll University of North Dakota, Minnesota State University Moorhead, Clemson University Advisor: Dr. Lara Pudwell Valparaiso

More information

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count Types of formulas for basic operation count Exact formula e.g., C(n) = n(n-1)/2 Algorithms, Design and Analysis Big-Oh analysis, Brute Force, Divide and conquer intro Formula indicating order of growth

More information

Topology Proceedings. COPYRIGHT c by Topology Proceedings. All rights reserved.

Topology Proceedings. COPYRIGHT c by Topology Proceedings. All rights reserved. Topology Proceedings Web: http://topology.auburn.edu/tp/ Mail: Topology Proceedings Department of Mathematics & Statistics Auburn University, Alabama 36849, USA E-mail: topolog@auburn.edu ISSN: 0146-4124

More information

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4

Homework #2 Solutions Due: September 5, for all n N n 3 = n2 (n + 1) 2 4 Do the following exercises from the text: Chapter (Section 3):, 1, 17(a)-(b), 3 Prove that 1 3 + 3 + + n 3 n (n + 1) for all n N Proof The proof is by induction on n For n N, let S(n) be the statement

More information

Discrete Applied Mathematics

Discrete Applied Mathematics Discrete Applied Mathematics 157 (2009 1696 1701 Contents lists available at ScienceDirect Discrete Applied Mathematics journal homepage: www.elsevier.com/locate/dam Riordan group involutions and the -sequence

More information

Intrinsic products and factorizations of matrices

Intrinsic products and factorizations of matrices Available online at www.sciencedirect.com Linear Algebra and its Applications 428 (2008) 5 3 www.elsevier.com/locate/laa Intrinsic products and factorizations of matrices Miroslav Fiedler Academy of Sciences

More information

Series of Error Terms for Rational Approximations of Irrational Numbers

Series of Error Terms for Rational Approximations of Irrational Numbers 2 3 47 6 23 Journal of Integer Sequences, Vol. 4 20, Article..4 Series of Error Terms for Rational Approximations of Irrational Numbers Carsten Elsner Fachhochschule für die Wirtschaft Hannover Freundallee

More information

Partition of Integers into Distinct Summands with Upper Bounds. Partition of Integers into Even Summands. An Example

Partition of Integers into Distinct Summands with Upper Bounds. Partition of Integers into Even Summands. An Example Partition of Integers into Even Summands We ask for the number of partitions of m Z + into positive even integers The desired number is the coefficient of x m in + x + x 4 + ) + x 4 + x 8 + ) + x 6 + x

More information

Theoretical Computer Science

Theoretical Computer Science Theoretical Computer Science 406 008) 3 4 Contents lists available at ScienceDirect Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs Discrete sets with minimal moment of inertia

More information

General Comments on Proofs by Mathematical Induction

General Comments on Proofs by Mathematical Induction Fall 2015: CMSC250 Notes on Mathematical Induction Proofs General Comments on Proofs by Mathematical Induction All proofs by Mathematical Induction should be in one of the styles below. If not there should

More information

The edge-diametric theorem in Hamming spaces

The edge-diametric theorem in Hamming spaces Discrete Applied Mathematics 56 2008 50 57 www.elsevier.com/locate/dam The edge-diametric theorem in Hamming spaces Christian Bey Otto-von-Guericke-Universität Magdeburg, Institut für Algebra und Geometrie,

More information

PROBABILITY AND STATISTICS IN COMPUTING. III. Discrete Random Variables Expectation and Deviations From: [5][7][6] German Hernandez

PROBABILITY AND STATISTICS IN COMPUTING. III. Discrete Random Variables Expectation and Deviations From: [5][7][6] German Hernandez Conditional PROBABILITY AND STATISTICS IN COMPUTING III. Discrete Random Variables and Deviations From: [5][7][6] Page of 46 German Hernandez Conditional. Random variables.. Measurable function Let (Ω,

More information

1 Sequences and Summation

1 Sequences and Summation 1 Sequences and Summation A sequence is a function whose domain is either all the integers between two given integers or all the integers greater than or equal to a given integer. For example, a m, a m+1,...,

More information

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Theoretical Computer Science. Completing a combinatorial proof of the rigidity of Sturmian words generated by morphisms

Theoretical Computer Science. Completing a combinatorial proof of the rigidity of Sturmian words generated by morphisms Theoretical Computer Science 428 (2012) 92 97 Contents lists available at SciVerse ScienceDirect Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs Note Completing a combinatorial

More information

Discrete Math Notes. Contents. William Farmer. April 8, Overview 3

Discrete Math Notes. Contents. William Farmer. April 8, Overview 3 April 8, 2014 Contents 1 Overview 3 2 Principles of Counting 3 2.1 Pigeon-Hole Principle........................ 3 2.2 Permutations and Combinations.................. 3 2.3 Binomial Coefficients.........................

More information

Introduction to Set Theory

Introduction to Set Theory Introduction to Set Theory George Voutsadakis 1 1 Mathematics and Computer Science Lake Superior State University LSSU Math 400 George Voutsadakis (LSSU) Set Theory June 2014 1 / 67 Outline 1 Ordinal Numbers

More information

CS 161 Summer 2009 Homework #2 Sample Solutions

CS 161 Summer 2009 Homework #2 Sample Solutions CS 161 Summer 2009 Homework #2 Sample Solutions Regrade Policy: If you believe an error has been made in the grading of your homework, you may resubmit it for a regrade. If the error consists of more than

More information

Divide and Conquer. Recurrence Relations

Divide and Conquer. Recurrence Relations Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.

More information

OPTIMAL bisections are needed for optimal VLSI layouts

OPTIMAL bisections are needed for optimal VLSI layouts International Journal of Computer, Electrical, Automation, Control and Information Engineering Vol:1, No:3, 007 A Proof for Bisection Width of Grids Kemal Efe and Gui-Liang Feng Abstract The optimal bisection

More information

Winkler s Hat Guessing Game: Better Results for Imbalanced Hat Distributions

Winkler s Hat Guessing Game: Better Results for Imbalanced Hat Distributions arxiv:1303.705v1 [math.co] 8 Mar 013 Winkler s Hat Guessing Game: Better Results for Imbalanced Hat Distributions Benjamin Doerr Max-Planck-Institute for Informatics 6613 Saarbrücken Germany April 5, 018

More information

On Power Series Analytic in the Open Unit Disk with Finite Doble-Logarithmic Order

On Power Series Analytic in the Open Unit Disk with Finite Doble-Logarithmic Order Applied Mathematical Sciences, Vol 2, 2008, no 32, 549-569 On Power Series Analytic in the Open Unit Disk with Finite Doble-Logarithmic Order Mehmet Açıkgöz University of Gaziantep, Faculty of Science

More information

Lecture Notes 1 Basic Concepts of Mathematics MATH 352

Lecture Notes 1 Basic Concepts of Mathematics MATH 352 Lecture Notes 1 Basic Concepts of Mathematics MATH 352 Ivan Avramidi New Mexico Institute of Mining and Technology Socorro, NM 87801 June 3, 2004 Author: Ivan Avramidi; File: absmath.tex; Date: June 11,

More information

Introduction to Divide and Conquer

Introduction to Divide and Conquer Introduction to Divide and Conquer Sorting with O(n log n) comparisons and integer multiplication faster than O(n 2 ) Periklis A. Papakonstantinou York University Consider a problem that admits a straightforward

More information

Week 4-5: Generating Permutations and Combinations

Week 4-5: Generating Permutations and Combinations Week 4-5: Generating Permutations and Combinations February 27, 2017 1 Generating Permutations We have learned that there are n! permutations of {1, 2,...,n}. It is important in many instances to generate

More information

Analysis of Algorithms. Randomizing Quicksort

Analysis of Algorithms. Randomizing Quicksort Analysis of Algorithms Randomizing Quicksort Randomizing Quicksort Randomly permute the elements of the input array before sorting OR... modify the PARTITION procedure At each step of the algorithm we

More information

Visual cryptography schemes with optimal pixel expansion

Visual cryptography schemes with optimal pixel expansion Theoretical Computer Science 369 (2006) 69 82 wwwelseviercom/locate/tcs Visual cryptography schemes with optimal pixel expansion Carlo Blundo a,, Stelvio Cimato b, Alfredo De Santis a a Dipartimento di

More information

Selection and Adversary Arguments. COMP 215 Lecture 19

Selection and Adversary Arguments. COMP 215 Lecture 19 Selection and Adversary Arguments COMP 215 Lecture 19 Selection Problems We want to find the k'th largest entry in an unsorted array. Could be the largest, smallest, median, etc. Ideas for an n lg n algorithm?

More information

A strongly polynomial algorithm for linear systems having a binary solution

A strongly polynomial algorithm for linear systems having a binary solution A strongly polynomial algorithm for linear systems having a binary solution Sergei Chubanov Institute of Information Systems at the University of Siegen, Germany e-mail: sergei.chubanov@uni-siegen.de 7th

More information

SOLUTIONS FOR 2012 APMO PROBLEMS

SOLUTIONS FOR 2012 APMO PROBLEMS Problem. SOLUTIONS FOR 0 APMO PROBLEMS Solution: Let us denote by XY Z the area of the triangle XY Z. Let x = P AB, y = P BC and z = P CA. From y : z = BCP : ACP = BF : AF = BP F : AP F = x : follows that

More information

CSE548, AMS542: Analysis of Algorithms, Spring 2014 Date: May 12. Final In-Class Exam. ( 2:35 PM 3:50 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Spring 2014 Date: May 12. Final In-Class Exam. ( 2:35 PM 3:50 PM : 75 Minutes ) CSE548, AMS54: Analysis of Algorithms, Spring 014 Date: May 1 Final In-Class Exam ( :35 PM 3:50 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your relative

More information

. As the binomial coefficients are integers we have that. 2 n(n 1).

. As the binomial coefficients are integers we have that. 2 n(n 1). Math 580 Homework. 1. Divisibility. Definition 1. Let a, b be integers with a 0. Then b divides b iff there is an integer k such that b = ka. In the case we write a b. In this case we also say a is a factor

More information

Codes for Partially Stuck-at Memory Cells

Codes for Partially Stuck-at Memory Cells 1 Codes for Partially Stuck-at Memory Cells Antonia Wachter-Zeh and Eitan Yaakobi Department of Computer Science Technion Israel Institute of Technology, Haifa, Israel Email: {antonia, yaakobi@cs.technion.ac.il

More information