Improved Master Theorems for Divide-and-Conquer Recurrences SALVADOR ROURA Universitat Politècnica de Catalunya, Barcelona, Catalonia, Spain Abstract. This paper presents new theorems to analyze divide-and-conquer recurrences, which improve other similar ones in several aspects. In particular, these theorems provide more information, free us almost completely from technicalities like floors and ceilings, and cover a wider set of toll functions and weight distributions, stochastic recurrences included. Categories and Subject Descriptors: F.2 [Analysis of Algorithms and Problem Complexity]; G.2.1 [Discrete Mathematics]: Combinatorics—recurrences and difference equations General Terms: Algorithms, Measurement, Performance Additional Key Words and Phrases: Asymptotic analysis, divide-and-conquer, master theorem 1. Introduction This work presents new theorems to solve many divide-and-conquer recurrences that arise in practice. Recall that a recurrence is a definition of a function F n in terms of the values of F at indices smaller than n; a recurrence is divide-andconquer—DAC, for short—if the average size of these indices is a fraction of n. Our reference source here is the Master Theorem—MT, for short—as it can be found in Sedgewick and Flajolet [1996]. Other references in this subject include the (classic) Master Theorem [Aho et al. 1974; Bentley et al. 1980; Cormen et al. 1990], several improvements [Kao 1997; Verma 1994; 1997; Wang and Fu 1996] as well as other related results [Karp 1994]. Assume that we have the recurrence F n ⫽ t n ⫹ W 䡠 F S n , with t n ⬎ 0 and S n ⫽ Z 䡠 n ⫹ ᏻ(1) for some 0 ⬍ Z ⬍ 1. If F n describes the cost to solve with a certain algorithm a problem of size n, then t n — customarily called toll function—is the cost of the divide and combine steps, W is the fixed number of This research was supported by the ESPRIT BRA Project ALCOM II, contract #7141, by the ESPRIT LTR Project ALCOM-IT, contract #20244 and by a grant from CIRIT (Comissió Interdepartamental de Recerca i Innovació Tecnològica). A previous version of this work was partially written while the author was visiting Princeton University. Author’s address: Departament de Llenguatges i Sistemes Informàtics, Universitat Politècnica de Catalunya, E-08028 Barcelona, Catalonia, Spain. E-mail: [email protected]. Permission to make digital / hard copy of part or all of this work for personal or classroom use is granted without fee provided that the copies are not made or distributed for profit or commercial advantage, the copyright notice, the title of the publication, and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery (ACM), Inc. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior specific permission and / or a fee. © 2001 ACM 0004-5411/01/0300-0170 $05.00 Journal of the ACM, Vol. 48, No. 2, March 2001, pp. 170 –205. Improved Master Theorems for Divide-and-Conquer Recurrences 171 recursive calls at each step, and S n is the size of the subproblems to be recursively solved. Let ␣ ⫽ ⫺logZ W. Then, the MT states that the solution to the recurrence is Fn ⫽ 冦 ⌰ 共 n ␣兲 , if ⌰共tn log n兲, if ⌰ 共 t n兲 , if tn ⫽ ᏻ共na兲 and a ⬍ ␣; tn ⫽ ⌰共n␣ logc n兲 and c ⱖ 0;1 tn ⫽ ⍀共na兲 and a ⬎ ␣. (To be completely rigorous, the last case above requires additional conditions of smoothness for the toll function t n .) Usually, a MT does not provide an explicit solution but partial information about the function under study, like bounds on its growing order. Nevertheless, a MT has two interesting properties: First, it typically provides results which rely exclusively upon the asymptotic behaviour of the toll function and of the distribution of weights; for instance, in the MT above we only use the main term of t n and the value ␣, which depends on W and Z. In particular, this means that the values of F n at small indices are irrelevant to most MTs. Second, a MT is easy and fast to use. As an example, we can solve the DAC recurrence M n ⫽ n ⫺ 1 ⫹ M n/ 2 ⫹ M n/ 2 (1) for n ⱖ 2, with M 0 ⫽ M 1 ⫽ 0, which defines the number of comparisons to sort an array of n keys with mergesort in the worst case [Flajolet and Golin 1994]. The term ᏻ(1) in the definition of S n covers expressions with floors and ceilings in the argument of the recursive call. Hence, a direct application of the rules above yields M n ⫽ ⌰(n log n). In this paper, we will make the MT more flexible and more informative. For instance, consider the recurrence Bn ⫽ 1 ⫹ 共 n ⫺ 1 兲 / 2 n 䡠 B (n⫺1)/ 2 ⫹ 共 n ⫺ 1 兲 / 2 n 䡠 B (n⫺1)/ 2 (2) for n ⱖ 2, with B 0 ⫽ 0 and B 1 ⫽ 1, which defines the expected number of steps of a binary search for a random key in an array of size n. This recurrence does not follow the MT pattern utterly, since we have 1 ⫺ 1/n expected recursive calls at each step. Therefore, to use the MT we must assume that the solution to the recurrence F n ⫽ 1 ⫹ F n/ 2 must be close to B n —which is true—, and conclude B n ⫽ ⌰(log n). We need a posterior reasoning to rigorously prove that this approximation does not lead to a wrong answer. By contrast, the MT presented in Section 2 directly deals with recurrences where the number of recursive calls is not constant but tends to a constant. As a consequence, we will get rid of the annoying technicalities related to factors with floors and ceilings. And we will see that in some cases it is possible to get the multiplying factor of the dominating term of the function under study. This improvements will yield the result B n ⫽ log2 n ⫹ o(log n) for the example above. 1 Through all this work, logc n means (log n) c . 172 SALVADOR ROURA Yet we will extend the MT further, to deal with recurrences where the asymptotic sizes of the subproblems to be recursively solved consist in several fixed fractions of the original problem,2 like 冉 冑冊 Fn ⫽ tn ⫹ 2 ⫺ 1 n F (n⫹1)/3 ⫹ 4F (n/ 2)⫺ 冑7 n ⫹ 冉 冊 1 2 ⫹ 1 n F (4n/5)⫹ln2 n (3) for n large enough. (Since all the theorems in this work rely only upon the asymptotic properties of the toll function and the distribution of weights, we can avoid explicitly stating the initial values of the recurrence.) It is frequent that the analysis of the cost of a given algorithm or data structure results in a stochastic recurrence, which does not follow any of the patterns mentioned above. As an example of stochastic recurrence, consider Qn ⫽ n ⫹ 1 ⫹ 2 n 冘 Qk (4) 0ⱕk⬍n for n ⱖ 1, with Q 0 ⫽ 0. This recurrence defines the expected number of comparisons to sort an n-key random array with quicksort. Clearly, the MTs we know so far cannot solve it, since the size of the subarrays to be recursively sorted is not fixed; it can be either an insignificant part of the whole input or almost it all. In this case, though, other techniques lead us to a closed solution [Hoare 1962]. Much more difficulties presents the analysis of the stochastic recurrence Qn ⫽ 1 ⫹ 4 n共n ⫹ 1兲 冘 共n ⫺ k兲Q k (5) 0ⱕk⬍n for n ⱖ 1, with Q 0 ⫽ 0, where Q n denotes the expected number of comparisons during a half-defined search in a random quad-tree of size n. An accurate asymptotic expression for Q n can be obtained after a thorough analysis by means of generating functions [Flajolet et al. 1993], but this technique requires a deep knowledge and expertise. Section 3 presents a new MT for stochastic recurrences, which shares the good properties of the MT in Section 2: it is simple and fast to use, and only the main term of t n and information on the asymptotic distribution of weights will be relevant. In addition, we will see how a simple iteration of the former MT sometimes yields several of the main terms of the function under study with their corresponding multiplicative factors. The rest of the paper is organized as follows: Sections 4 and 5 present general-purpose theorems that solve many DAC recurrences that do not have to follow any particular pattern. Those theorems will allow us to prove in Sections 6 and 7 the MTs given in Sections 2 and 3, but also have other applications. For 2 To the best of the author’s knowledge, Kao [1997] was the first to develop a basic MT for this kind of recurrences in 1986 (personal communications). Some additional results about these recurrences may be found in Verma [1997]. Improved Master Theorems for Divide-and-Conquer Recurrences 173 instance, they are useful for the analysis and asymptotic improvement of quicksort and quickselect [Martı́nez and Roura 1998]. In Section 8, we will see that it is possible to directly compute the main term of the variance of the cost of some algorithms, if the nonrecursive cost is large enough and the algorithm follows one of two typical patterns (quickselect and quicksort are prototypical examples of those patterns). Finally, Section 9 presents some open problems. Preliminary versions of this work appeared in Roura [1997a; 1997b]. 2. The Discrete Master Theorem In this section, we cast in the form of a Master Theorem some of the results that will be proved in latter sections. This MT deals with recurrences like (1), (2), and (3), where the problem is broken into pieces such that the asymptotic size of each one is a fixed fraction of the size of the whole problem. We call them discrete recursive definitions. Definition 2.1. We say that Fn ⫽ 再 bn , tn ⫹ 冘 1ⱕdⱕD if Rd,nFSd, n , if 0ⱕn⬍N nⱖN is a discrete recursive definition of F n iff D ⱖ 1; R d, n ⫽ w d ⫹ r d, n ⱖ 0, where w d ⬎ 0 and 兺 1ⱕdⱕD 兩r d, n 兩 ⫽ ᏻ(n ⫺ ) for some ⬎ 0; and S d, n ⫽ z d 䡠 n ⫹ s d, n , where 0 ⬍ z d ⬍ 1 and 兺 1ⱕdⱕD 兩s d, n 兩/n ⫽ ᏻ(n ⫺ ) for some ⬎ 0. Here, D is the finite number of subproblems to be recursively solved; R d, n is the number of recursive calls to deal with the dth subproblem, where w d is the asymptotic number of calls to it; and S d, n is the (integer) size of the dth subproblem, where z d is the asymptotic fraction of the original problem to be solved by the dth recursive call. For example, (1) is a discrete recursive definition. There we have two subproblems to recursively deal with: D ⫽ 2; whose size is asymptotically 1/2 of the size of the original problem: z 1 ⫽ z 2 ⫽ 1/ 2, ⫺1 ⱕ s 1, n ⱕ 0, 0 ⱕ s 2, n ⱕ 1; and there is exactly one call to each one: w 1 ⫽ w 2 ⫽ 1, r 1, n ⫽ r 2, n ⫽ 0. For the bounds of s n, k , we have used the fact that r ⫺ 1 ⱕ r ⱕ r and r ⱕ r ⱕ r ⫹ 1 for every real r. Notice that ⫽ ⫽ 1 is a possible choice in this example. The Discrete MT (Theorem 2.3) covers the presence of sublogarithmical factors in the toll function, that is, factors whose growing order is smaller than log n for any ⬎ 0. This allows us to deal with toll functions like t n ⫽ n 2 ln3 n 䡠 ln ln n, for instance. We define precisely this concept. Definition 2.2. Let n be a strictly positive nondecreasing function for large n. Moreover, assume that for every ⬎ 0 the function log n/ n is increasing as long as n is large enough. Then we say that n is a sublogarithmical function. Now we are ready to state the Discrete MT (examples of its use can be found in Appendix A). THEOREM 2.3 (DISCRETE MASTER THEOREM). Let Fn be a function defined by a discrete recursive definition, and let B na lnc n 䡠 n be the main term of tn, where B ⬎ 0, a and c are arbitrary constants, and n ⫽ n or n ⫽ 1/n for some 174 SALVADOR ROURA sublogarithmical function n. Let ⌽( x) ⫽ 兺1ⱕdⱕD wd 䡠 ( zd)x, and Ᏼ ⫽ 1 ⫺ ⌽(a). Then, (1) if Ᏼ ⬎ 0, then F n ⬃ t n /Ᏼ; (2) if Ᏼ ⫽ 0, then (2.1) if c ⬎ ⫺1, then F n ⬃ t n ln n/Ᏼ⬘, where Ᏼ⬘ ⫽ ⫺(c ⫹ 1)兺 1ⱕdⱕD w d 䡠 ( z d ) a ln z d ; (2.2) if c ⫽ ⫺1, then F n ⫽ ᏻ(n a log n) for any ⬎ 0, and F n ⫽ ⍀(n a ) if F n ⱖ 0 for every n ⱖ 0; (2.2⬘) if c ⫽ ⫺1 and n ⫽ 1, then F n ⬃ t n ln n 䡠 ln ln n/Ᏼ⬙, where Ᏼ⬙ ⫽ ⫺兺 1ⱕdⱕD w d 䡠 ( z d ) a ln z d ; (2.3) if c ⬍ ⫺1, then F n ⫽ ᏻ(n a ) (F n ⫽ ⌰(n a ), if F n ⱖ 0 for every n ⱖ 0); (3) if Ᏼ ⬍ 0, then F n ⫽ ᏻ(n ␣ ) (F n ⫽ ⌰(n ␣ ), if F n ⱖ 0 for every n ⱖ 0), where ␣ is the unique solution of ⌽( ␣ ) ⫽ 1. PROOF. Section 6 is devoted to prove this theorem. e The Discrete MT could be trivially adapted to deal with negative toll functions by changing the conditions “B ⬎ 0” and “F n ⱖ 0 for every n ⱖ 0” to “B ⬍ 0” and “F n ⱕ 0 for every n ⱖ 0”, respectively. Also, though we will not prove it in this work, we could relax Definition 2.1 to permit the value z d ⫽ 1 for some indices, as long as (a) there is, at least, one index d such that 0 ⬍ z d ⬍ 1; and (b) the total sum of weights w d of the indices d with z d ⫽ 1 is strictly smaller than 1. Notice that neither A n ⫽ t n ⫹ A n⫺3 (6) B n ⫽ t n ⫹ 2B n/ 2 ⫹ 2B n⫺1 (7) nor is, even under the relaxation above, a discrete recursive definition. The first recurrence does not satisfy any of the two conditions, while the second recurrence fails to fulfill the condition (b). They are out of the scope of this paper. By contrast, the recurrence F n ⫽ t n ⫹ F n/ 2 ⫹ 1 2 䡠 F n⫺2 is a discrete recursive definition, and so we could analyze it exactly as stated by the Discrete MT. The case z d ⫽ 0 for some indices 1 ⱕ d ⱕ D is especially awkward. We avoid dealing with it. 3. The Continuous Master Theorem This section covers the analysis of recurrences like (4) and (5), which we will call continuous. But first we need to define the concept of shape function (the reason for this name will be clear after Definition 3.2). Improved Master Theorems for Divide-and-Conquer Recurrences 175 Definition 3.1. Let ( z) ⱖ 0 be a function over [0, 1] such that 兰 10 ( z) dz exists and is at least 1. Furthermore, assume that there is some ⬍ 0 such that 兰 10 ( z) z dz also converges.3 Then we say that ( z) is a shape function. Definition 3.2. We say that Fn ⫽ 再 bn , tn ⫹ 0ⱕn⬍N if 冘 0ⱕk⬍n n,kFk , if nⱖN is a continuous recursive definition of F n iff there exist some shape function ( z), some constant 0 ⬍ q ⱕ 1 and some function M n ⫽ ⌰(n q ) with integer values such that, if we define z n, j ⫽ j/M n for every 0 ⱕ j ⱕ M n , I n, j ⫽ [ z n, j 䡠 n, z n, j⫹1 䡠 n) for every 0 ⱕ j ⬍ M n , and n, j ⫽ 冏冘 冕 n, k ⫺ k僆I n, j z n, j⫹1 共 z 兲 dz z n, j 冏 (8) for every 0 ⱕ j ⬍ M n , then 兺 0ⱕj⬍M n n, j ⫽ ᏻ(n ⫺ ) for some ⬎ 0. Usually, M n ⫽ n is a possible choice, and in this case (8) reduces to 冏 n, k ⫽ n, k ⫺ 冕 (k⫹1)/n 冏 共 z 兲 dz . k/n Loosely speaking, we can use the integral in the expression above to find a good approximation to n, k . Notice that there can only be one shape function ( z) related to a given continuous recursive definition, except for bizarre shape functions obtained from ( z) by changing its value at a finite number of points, or by similar minor perturbations. For instance, consider the recurrence Sn ⫽ n ⫹ 1 ⫹ 冘 2 n2 kS k (9) 0ⱕk⬍n for the expected number of comparisons to select the ith out of n keys using quickselect—also known as FIND [Hoare 1961]—when i is chosen at random. Its shape function is ( z) ⫽ 2z (see Figure 1), since 冕 (k⫹1)/n k/n 共 z 兲 dz ⫽ 冕 (k⫹1)/n k/n 2z dz ⫽ z 2 冏 (k⫹1)/n ⫽ k/n 2k n 2 ⫹ 1 n 2 ⫽ n, k ⫹ 1 n2 , and hence n, k ⫽ 1/n 2 and 兺 0ⱕk⬍n n, k ⫽ 1/n ⫽ ᏻ(n ⫺ ) with ⫽ 1. Therefore, ( z) is nothing except the asymptotic shape of the distribution of weights, which now is very similar to a continuous probability distribution, where the area beneath the function is the asymptotic number of recursive calls. Since, by definition, 兰 10 ( z) dz ⱖ 1, we are assuming that there is at least one 3 The author’s conjecture is that this technical property is always true if 兰10 ( z) dz exists and is at least 1. Section 7 provides more details. 176 SALVADOR ROURA FIG. 1. Shape function for FIND. recursive call for large n. This condition (very likely to hold in practice) simplifies the study of these recurrences. On the other hand, we have allowed M n to be ⌰(n q ) for some q ⱕ 1, as long as q ⬎ 0. So it is not necessary that ( z) fits the n weights individually, but a polynomial number of groups of weights. This relaxation could be useful when dealing with particularly difficult recurrences. THEOREM 3.3 (CONTINUOUS MASTER THEOREM). Let Fn be a function defined by a continuous recursive definition, and let B na lnc n 䡠 n be the main term of tn, where B ⬎ 0, a and c are arbitrary constants, and n ⫽ n or n ⫽ 1/n for some sublogarithmical function n. Let ( x) ⫽ 兰10 ( z) zx dz, and Ᏼ ⫽ 1 ⫺ (a). Then, (1) if Ᏼ ⬎ 0, then F n ⬃ t n /Ᏼ; (2) if Ᏼ ⫽ 0, then (2.1) if c ⬎ ⫺1, then F n ⬃ t n ln n/Ᏼ⬘, where Ᏼ⬘ ⫽ ⫺(c ⫹ 1) 兰 10 ( z) z a ln z dz; (2.2) if c ⫽ ⫺1, then F n ⫽ ᏻ(n a log n) for any ⬎ 0, and F n ⫽ ⍀(n a ) if F n ⱖ 0 for every n ⱖ 0; (2.2⬘) if c ⫽ ⫺1 and n ⫽ 1, then F n ⬃ t n ln n 䡠 ln ln n/Ᏼ⬙, where Ᏼ⬙ ⫽ ⫺兰 10 ( z) z a ln z dz; (2.3) if c ⬍ ⫺1, then F n ⫽ ᏻ(n a ) (F n ⫽ ⌰(n a ), if F n ⱖ 0 for every n ⱖ 0); (3) if Ᏼ ⬍ 0 (including the case Ᏼ ⫽ ⫺⬁) then F n ⫽ ᏻ(n ␣ ) (F n ⫽ ⌰(n ␣ ), if F n ⱖ 0 for every n ⱖ 0), where ␣ is the unique solution of ( ␣ ) ⫽ 1. PROOF. Section 7 is devoted to prove this theorem. e To use the Continuous Master Theorem, we must first identify the shape function ( z) for the distribution of weights. This is equivalent to identifying the values {w d } 1ⱕdⱕD and { z d } 1ⱕdⱕD for the discrete case. One possibility is to conjecture that ( z) ⫽ n 䡠 n, zn . For instance, for (9) this technique yields ( z) ⫽ n 䡠 2/n 2 䡠 zn ⫽ 2z, which we have already proved to be right. But for (5) we have additional problems, since the expression n 䡠 n, zn ⫽ 4(1 ⫺ z)/(1 ⫹ Improved Master Theorems for Divide-and-Conquer Recurrences 177 1/n) includes n. Lemma 7.2 in Section 7 provides a way to find ( z) that works in many practical situations. Examples of how to use the Continuous Master Theorem can be found in Appendix B. 4. The Core Theorems In this section and Section 5, we will prove some general theorems that apply to many DAC recurrences. In Sections 6 and 7, we will see how to use these results to prove the statements of both the Discrete and the Continuous MTs. We begin introducing the concept of divide-and-conquer recursive definition formally. Definition 4.1. Let F n be a function defined for every n ⱖ 0, and let 0ⱕk⬍n Ᏺ ⫽ 关 N, 兵 b n 其 0ⱕn⬍N , 兵 t n 其 nⱖN , 兵 w n, k 其 nⱖN 兴 be a recursive definition, with N ⱖ 1 and w n, k ⱖ 0. For every n ⱖ N, let W n ⫽ 兺 0ⱕk⬍n w n, k and Z n ⫽ 兺 0ⱕk⬍n (w n, k /W n )(k/n). Then we say that Ᏺ is a DAC recursive definition of F n if and only if (a) F n ⫽ b n for every 0 ⱕ n ⬍ N; (b) for every n ⱖ N, Fn ⫽ tn ⫹ 冘 w n, k F k ; (10) 0ⱕk⬍n and (c) it exists some upper bound U ⬍ 1 such that Z n ⱕ U for all n large enough. We also define W ⫽ limn3⬁ W n and Z ⫽ limn3⬁ Z n , if they exist. This definition can be easily interpreted: W n is the total number of recursive calls to solve a problem of size n; Z n is the average fraction of the original problem that is solved by a recursive call (it turns out that 0 ⱕ Z n ⬍ 1); and for large n, the average size of the recursive calls is, at most, a fraction of the whole problem. For example, for (9), we have W n ⫽ 1 ⫺ 1/n, W ⫽ 1, Z n ⫽ 2/3 ⫺ 1/3n and Z ⫽ 2/3, while for (1) we have W n ⫽ 2, W ⫽ 2, Z n ⫽ 1/ 2 and Z ⫽ 1/ 2. By contrast, (6) is not a DAC recursive definition. Most of the results from which both MTs are derived refer to canonical recursive definitions, which are defined as follows: Definition 4.2. Let Ᏺ be a DAC recursive definition of a function F n . We say that Ᏺ is a canonical recursive definition if and only if both these properties hold: (a) The constant W exists and is equal to 1. (b) If we define m n ⫽ W n ⫺ W, then 兩m n 兩 ⫽ ᏻ(n ⫺ ) for some ⬎ 0. Hence, a DAC recursive definition is canonical if the number of recursive calls tends to 1, with a minimum convergence speed. For instance, for (9), we have W ⫽ 1, and 兩m n 兩 ⫽ 1/n ⫽ ᏻ(n ⫺ ) with ⫽ 1. Now, assume that F n ⱖ 0 is defined by (10). Then we have F n ⫽ ⍀(t n ), because F n cannot grow more slowly than t n does. So the question is identifying under which conditions F n can grow faster than t n . For the recursive definitions we deal with and roughly speaking, we will prove that there is a growing order ⌰(n ␣ ) associated to every distribution of weights, irrespectively of how small t n 178 SALVADOR ROURA is. This would be similar to state that F n ⫽ ⌰(max{t n , n ␣ }), which is almost true. For instance, consider the recurrence F n ⫽ t n ⫹ F n/4 . (11) We will see in this section that ␣ ⫽ 0 for any canonical recurrence, such as this one. Therefore, for “large” values of t n (case 1 of the MTs) like n, n 3 or even 2 n , we should get F n ⫽ ⌰(t n ), which is true. For “small” values of t n (case 3 of the MTs) like 1/n, 1/n 3 or 2 ⫺n , F n should be ⌰(1), which is also true. However, things are not so easy for values of t n close to ⌰(1) (case 2 of the MTs). For example, for t n ⫽ 1 the growing order of F n turns out to be ⌰(log n) instead of ⌰(1). We will see in Section 5 why this additional factor appears. At this point, it is worth commenting on the word “Core” in the title of this section. It tries to suggest the idea that recursive definitions with a toll function small enough—and thus inside the zone dominated by the term ⌰(n ␣ ) associated to the distribution of weights—are the most difficult to analyze. Indeed, there is no way to find the lower order terms of F n nor even the multiplicative factor of the main term n ␣ , but to consider all the values of F n , the values at small indices included. For example, consider (11), and assume that it holds for n ⱖ 1. Let t n ⬎ 0 be small enough. Then F n ⫽ ⌰(1), but modifying F 0 yields a significant change in F n for every n. In fact, changing the value of the function at any index significantly affects F at an infinite number of indices. Set in terms of a recursion tree (see Cormen et al. [1990], for example), the solution to the recurrence is dominated by the values at the leaves. Moreover, in some cases, the multiplicative factor of the main term n ␣ is not even asymptotically constant. Consider the following recurrence, Fn ⫽ tn ⫹ 再 F 2n/4 , if F2(n⫺1)/4⫹1 , if n is even n is odd for every n ⱖ 2. Let t n ⬎ 0 be small enough and such that t 2n ⫽ t 2n⫹1 , and let F 0 ⫽ 0 and F 1 ⫽ 1. Then it is easy to see that F n ⫽ ⌰(1), but F n cannot tend to a constant, since it fluctuates periodically. We end this section with two theorems which formalize one of the claims above, namely that any canonical recurrence is on the one hand ⍀(1), and on the other hand ᏻ(1) for t n small enough. The three technical conditions in the statement of Theorem 4.3 typically hold and, loosely speaking, avoid cases like “everything is zero” and “the negative and the positive contributions cancel out.” THEOREM 4.3. Let Fn be defined by a canonical recursive definition, and let bn ⱖ 0, tn ⬎ 0 and 兺0ⱕk⬍N wn,k ⫽ ᏻ(n⫺) for some ⬎ 0. Then Fn ⫽ ⍀(1). PROOF. By hypothesis, 兩m n 兩 ⫽ 兩W n ⫺ 1兩 ⫽ ᏻ(n ⫺ ), where ⬎ 0. Choose some such that 0 ⬍ ⬍ max{, }, and define W⬘n ⫽ 兺 Nⱕk⬍n w n, k . Taking into account that W n ⱖ 1 ⫺ 兩m n 兩, we have W⬘n ⫽ W n ⫺ 兺 0ⱕk⬍N w n, k ⱖ 1 ⫹ ᏻ(n ⫺ ) ⫺ ᏻ(n ⫺ ) ⱖ 1 ⫺ n ⫺ , as long as n is large enough. Improved Master Theorems for Divide-and-Conquer Recurrences 179 Now define Z⬘n ⫽ 冘 Nⱕk⬍n w n, k 1⫺n ⫺ 䡠 k n ⱕ 冘 wn,k k Wn Wn 䡠 ⫽ 䡠 Zn ⱕ 䡠 U, ⫺ 1⫺n 1 ⫺ n ⫺ 0ⱕk⬍n Wn n Wn 1⫺n ⫺ where 0 ⬍ U ⬍ 1 is the upper bound for the Z n ’s that exists by definition. Choose any V such that U ⬍ V ⬍ 1. Then it is clear that Z⬘n ⱕ V for large n. For the next step of the proof, choose some N⬘ ⬎ N large enough to get W⬘n ⱖ 1 ⫺ n ⫺ , Z⬘n ⱕ V, and also n ⫺ ⱕ 1/ 2 for every n ⱖ N⬘. Let h( x) ⫽ exp(2V /(1 ⫺ V ) x ). In what follows, we will use the easy-to-prove fact that h( x) ⱖ 1 is a decreasing convex function in the interval [1, ⫹⬁). Set M ⫽ min{F n /h(n)} Nⱕn⬍N⬘ . Notice that b n ⱖ 0 and t n ⬎ 0 imply M ⬎ 0. We can prove by induction that F n ⱖ M 䡠 h(n) holds not only for all N ⱕ n ⬍ N⬘ but also for all n ⱖ N⬘: Assuming the induction hypothesis, we have Fn ⫽ tn ⫹ 冘 i.h. w n, k F k ⱖ 冘 wn,kM 䡠 h共k兲 ⫽ M 䡠 W⬘n Nⱕk⬍n 0ⱕk⬍n 冘 Nⱕk⬍n wn,k W⬘n 䡠 h共k兲. The convexity of h( x), the bound for W⬘n and the fact that h( x) is decreasing yields F n ⱖ M 䡠 W⬘n 䡠 h 冉 冘 Nⱕk⬍n w n, k W⬘n 冊 䡠 k ⱖ M 共 1 ⫺ n ⫺兲 䡠 h 冉 冘 Nⱕk⬍n wn,k 1 ⫺ n ⫺ 冊 䡠k . From the definition of Z⬘n , F n ⱖ M(1 ⫺ n ⫺ ) 䡠 h(nZ⬘n ). Taking into account that 1 ⫺ x ⱖ exp(⫺2x) for all 0 ⱕ x ⱕ 1/ 2, and replacing x by n ⫺ , we get 1 ⫺ n ⫺ ⱖ exp(⫺2n ⫺ ). Furthermore, Z⬘n ⱕ V and h( x) is decreasing, and thus we have F n ⱖ M exp(⫺2n ⫺ ) 䡠 h(nV) ⫽ M 䡠 h(n), the last step obtained through simple manipulations. This ends the inductive proof. Finally, h(n) ⱖ 1 yields F n ⱖ M ⬎ 0 for every n ⱖ N, and the statement of the theorem follows. e THEOREM 4.4. Let Fn be defined by a canonical recursive definition, and let tn ⫽ ᏻ(logc n) for some c ⬍ ⫺1. Then Fn ⫽ ᏻ(1). PROOF. Let Ᏺ be the recursive definition for F n . First of all, we introduce a recursive definition Ᏻ for a new function G n , by modifying Ᏺ as follows: Let n, k denote the weights of Ᏺ, Y n denote 兺 0ⱕk⬍n n, k , and assume without loss of generality that Y n ⬎ 0—recall that limn3⫹⬁ Y n ⫽ 1. Define w n, k , the weights of Ᏻ, to be equal to n, k if Y n ⱖ 1, and equal to n, k /Y n if Y n ⬍ 1 (this is just a normalization of the weights so that they sum at least 1). Let u n be the toll function of Ᏺ; we define the toll function of Ᏻ as t n ⫽ 兩u n 兩. Altogether, ⫺G n ⱕ F n ⱕ G n trivially holds for every n ⱖ 0, so it is enough to bound G n by above to prove the theorem. Let W n , W, etc. be as in Definitions 4.1 and 4.2 but for the set of weights w n, k of Ᏻ. Then, on the one hand, we have that W is still 1, but now W n ⱖ 1 and m n ⱖ 0. On the other hand Z n remains the same and hence Z n ⱕ U for some 0 ⬍ U ⬍ 1. Choose some V such that U ⬍ V ⬍ 1, and some such that 0 ⬍ ⬍ , where ⬎ 0 is the constant in Definition 4.2. Choose some a ⱖ 1 large 180 SALVADOR ROURA enough to get V /(1 ⫺ V ) ⱕ a . We introduce two auxiliar functions, f( x) ⫽ exp(⫺V /(1 ⫺ V )( x ⫹ a) ), and g( x) ⫽ 兺 iⱖ1 g i ( x) c , where g i ( x) ⫽ ln( x ⫹ a) ⫺ i ln V. It is not difficult to prove that, for every x ⱖ 0, 0 ⬍ f( x) ⱕ 1 is an increasing concave function, and g( x) ⱖ 0 is a well-defined decreasing convex function. There are three bounds for the quantities introduced so far that we will find helpful through this proof (they all hold for n large enough, say for n ⱖ N⬘ for some constant N⬘). First, taking into account that m n ⫽ ᏻ(n ⫺ ), we have 0 ⱕ m n ⱕ 1/((n ⫹ a) ⫹ 1). Second, we define Z⬘n ⫽ (nZ n ⫹ a)/(n ⫹ a) ⫽ Z n ⫹ a(1 ⫺ Z n )/(n ⫹ a) ⱕ U ⫹ a/n ⱕ V. Finally, by the initial hypothesis about t n we know that there exists some constant K ⬎ 0 such that t n ⱕ K lnc (n ⫹ a). Assume n ⱖ N⬘, and introduce Sn ⫽ 冘 冘 w n, k f 共 k 兲 ⫽ 0ⱕk⬍n w n, k 0ⱕk⬍n Wn 䡠 f共k兲 ⫹ mn Wn 冘 w n, k f 共 k 兲 , 0ⱕk⬍n where for the second equality above we have used the fact that W n ⫽ 1 ⫹ m n . Then, since f( x) is positive, increasing and concave, and m n is positive, we can bound S n to get Sn ⱕ f 冉 冘 w n, k 0ⱕk⬍n Wn 冊 䡠k ⫹ mn Wn 䡠 W n f 共 n 兲 ⫽ f 共 nZ n 兲 ⫹ m n f 共 n 兲 . By the definition of Z⬘n , we know that nZ n ⫹ a ⫽ (n ⫹ a) Z⬘n ⱕ (n ⫹ a)V. Therefore, f 共 nZ n 兲 ⫽ exp 冉 ⫺V 共1 ⫺ V 兲共nZn ⫹ a兲 冊 冉 ⱕ exp ⫺1 共1 ⫺ V兲共n ⫹ a兲 冊 . (12) For the next step we use an auxiliar function A n ⫽ 1 ⫺ 1/((n ⫹ a) ⫹ 1) ⫽ (n ⫹ a) /((n ⫹ a) ⫹ 1). Since 1/A n ⫽ 1 ⫹ 1/(n ⫹ a) , and 1 ⫹ x ⱕ exp( x) for every x ⱖ 0, it follows that 1/A n ⱕ exp(1/(n ⫹ a) ), and thus A n ⱖ exp(⫺1/(n ⫹ a) ). Hence, A n f(n) ⱖ exp(⫺1/(n ⫹ a) ) f(n) ⫽ exp(⫺(1 ⫺ V )/(n ⫹ a) ), and from (12), m n ⱕ 1/((n ⫹ a) ⫹ 1), and the definition of A n we conclude S n ⱕ f(n). We will use this inequality in a moment. Now introduce R n ⫽ 兺 0ⱕk⬍n w n, k g(k), and use the convexity of g( x) to get Rn ⱖ 冘 0ⱕk⬍n w n, k Wn 䡠 g共k兲 ⱖ g 冉冘 0ⱕk⬍n w n, k Wn 冊 䡠 k ⫽ g 共 nZ n 兲 ⫽ 冘 g 共 nZ 兲 . i n c iⱖ1 By definition, g i (nZ n ) ⫽ ln(nZ n ⫹ a) ⫺ i ln V ⫽ ln((n ⫹ a) Z⬘n ) ⫺ i ln V. Assume n ⱖ N⬘; the bound for Z⬘n yields g i (nZ n ) ⱕ ln(n ⫹ a) ⫹ ln V ⫺ i ln V ⫽ g i⫺1 (n). Therefore, R n ⱖ 兺 iⱖ1 g i⫺1 (n) c ⫽ lnc (n ⫹ a) ⫹ g(n). We are ready to prove the theorem. Set M ⫽ max{(G n /K ⫹ g(n))/ f(n)} 0ⱕn⬍N⬘ . Then we have G n /K ⱕ M 䡠 f(n) ⫺ g(n) for any n ⬍ N⬘. We can Improved Master Theorems for Divide-and-Conquer Recurrences 181 prove this bound by induction when n ⱖ N⬘: Gn K ⫽ tn K ⫹ 冘 0ⱕk⬍n w n, k 䡠 Gk K i.h. ⱖ lnc共n ⫹ a兲 ⫹ 冘 wn,k共M 䡠 f共k兲 ⫺ g共k兲兲 0ⱕk⬍n ⫽M 䡠 Sn ⫹ lnc共n ⫹ a兲 ⫺ Rn ⱕ M 䡠 f共n兲 ⫺ g共n兲. Finally, we have F n ⱕ G n ⱕ K(M 䡠 f(n) ⫺ g(n)) ⱕ K 䡠 M for every n ⱖ 0 (and F n ⱖ ⫺K 䡠 M), and the theorem is proved. e 5. The Flesh Theorems In this section, we deal with the canonical recursive definitions whose toll function is large enough to dominate the solution. These recurrences are typically easier to analyze than those in Section 4 (and thus the “Flesh” in the title), and in most cases we can get the multiplicative factor of the main term of the function under study. Moreover, sometimes it is possible to extract one by one several main terms with their multiplicative factors, until the core is reached (see Appendix B). The reason for the name chosen in the following definition will be clear after Theorem 5.3. Definition 5.1. Let un be a function over the integers. We say that ␥n is a bounding function of un if and only if there exist some constant N␥ ⱖ 1 and some strictly positive nonincreasing function ( z) defined over (0, 1) such that (a) un␥n ⫺ uk␥k ⱖ (k/n)un for every n ⬎ N␥ and every N␥ ⱕ k ⬍ n; (b) un, ␥n ⬎ 0 for every n ⱖ N␥; (c) ␥n is a subpolynomial function; and (d) un␥n ⫽ (1). For instance, ␥ n ⫽ 1 is a bounding function of u n ⫽ n 2 . Take  ( z) ⫽ 1 ⫺ z 2 . Then we have u n ␥ n ⫺ u k ␥ k ⫽ n 2 ⫺ k 2 ⫽ (1 ⫺ (k/n) 2 )n 2 ⫽  (k/n)u n . The other conditions trivially hold. The word “entropy” is defined below with a meaning wider than usually. Our definition reduces to the traditional one when t n ⫽ 1 and ␥ n ⫽ log2 n. Definition 5.2. Let Ᏺ be a canonical recursive definition of a function F n , and let ␥ n be a bounding function of t n . We define the entropy of Ᏺ with respect to ␥ n at every n ⱖ max{N, N ␥ } as Ᏼ n( ␥ ) ⫽ ␥ n ⫺ 冘 w n, k 䡠 N ␥ ⱕk⬍n tk tn 䡠 ␥k . (13) We also define Ᏼ(␥) ⫽ limn3⬁ Ᏼ n( ␥ ) , if it exists. The next theorem, together with Lemma 5.4, will allow us to bound the solution of many canonical recursive definitions. THEOREM 5.3. Let Fn be defined by a canonical recursive definition, and let ␥n be a bounding function of un. If tn ⫽ ᏻ(un), then Fn ⫽ ᏻ(un␥n). If tn ⫽ o(un), then Fn ⫽ o(un␥n). PROOF. Let Ᏼ n( ␥ ) be defined as in (13) but using u n instead of t n . We first prove that Ᏼ n( ␥ ) ⫽ ⍀(1), as follows. We know that Z n ⱕ U for large n, where 0 ⬍ U ⬍ 1. Choose some V such that U ⬍ V ⬍ 1, and let n be large enough to 182 SALVADOR ROURA get nV ⬎ N ␥ . Then t n ␥ n ⬎ t n ␥ n ⫺ t k ␥ k ⱖ  (k/n)t n ⱖ  (V)t n for every N ␥ ⱕ k ⬍ nV. Alternatively, we can write ␥ n ⬎ ␥ n ⫺ t k /t n 䡠 ␥ k ⱖ  (V). We now use these bounds in the definition of Ᏼ n( ␥ ) : Ᏼ n( ␥ ) ⫽ 冉冘 冊 w n, k ⫺ m n ␥ n ⫺ 0ⱕk⬍n 冘 冘 ⱖ ⱖ 冉 tk wn,k ␥n ⫺ N␥ⱕk⬍nV 0ⱕk⬍N␥ w n, k 䡠 N ␥ ⱕk⬍n 冘 wn,k␥n ⫹ 冘 tn tk tn 䡠 ␥k 冊 䡠 ␥ k ⫺ m n␥ n wn,k共V兲 ⫺ mn␥n . 0ⱕk⬍nV On the other hand, from V 冘 冘 w n, k ⫽ nVⱕk⬍n w n, k 䡠 nV nVⱕk⬍n n 冘 ⱕ w n, k 䡠 0ⱕk⬍n k n ⫽ Z nW n ⱕ U 䡠 W n , we have 兺0ⱕk⬍nV wn,k ⫽ Wn ⫺ 兺nVⱕk⬍n wn,k ⱖ (1 ⫺ U/V)Wn. Altogether, we deduce Ᏼn(␥) ⱖ (1 ⫺ U/V)(V)Wn ⫺ mn␥n. But mn␥n vanishes for large n, because 兩mn兩 ⫽ ᏻ(n⫺) for some ⬎ 0 and ␥n is a subpolynomial function. Therefore, since 1 ⫺ U/V ⬎ 0, (V) ⬎ 0 and Wn tends to W ⫽ 1, we have Ᏼn ⱖ Q for some constant Q ⬎ 0 and n large enough (say, larger than some constant NᏴ). Now we can prove the ᏻ case. Since t n ⫽ ᏻ(u n ), there exist constants K ⬎ 0 and M such that 兩t n 兩 ⱕ Ku n for every n ⱖ M. Choose M to be at least N Ᏼ , and introduce a new function, Gn ⫽ 再 Fn , Kun ⫹ 0ⱕn⬍M if w G , if n,k k 0ⱕk⬍n 冘 n ⱖ M. A simple proof by induction yields ⫺G n ⱕ F n ⱕ G n for every n. Now define In ⫽ 冦 Gn , if Gn ⫺ K Q 䡠 un␥n , if 0 ⱕ n ⬍ N␥ n ⱖ N␥ . Let n ⱖ M. Using the definitions of I n and G n in the first step, and the definition of I n back in the second step, we get I n ⫽ Ku n ⫹ 冘 K w n, k G k ⫺ Q 0ⱕk⬍n ⫽ Kun ⫺ ⫽ Kun ⫺ K Q K Q 冉 u n␥ n ⫺ 䡠 u nᏴ n ⫹ 䡠 u n␥ n 冊 冘 wn,kuk␥k ⫹ 冘 wn,kIk . N␥ⱕk⬍n 0ⱕk⬍n 冘 0ⱕk⬍n wn,kIk Improved Master Theorems for Divide-and-Conquer Recurrences 183 From the bound for Ᏼ n , the toll function above is ⱕ Ku n ⫺ K/Q 䡠 u n Q ⫽ 0, as long as n ⱖ M. Therefore, if we define Jn ⫽ 再冘 兩I n 兩, 0ⱕk⬍n if wn,k Jk , if 0ⱕn⬍M n ⱖ M, then we have I n ⱕ J n . But according to Theorem 4.4, J n ⫽ ᏻ(1), that is, J n ⱕ S for some constant S ⬎ 0 and n large enough. This implies I n ⱕ S as well, and hence F n ⱕ G n ⫽ I n ⫹ K/Q 䡠 u n ␥ n ⱕ S ⫹ K/Q 䡠 u n ␥ n or alternatively, F n /u n ␥ n ⱕ S/u n ␥ n ⫹ K/Q. Taking into account that u n ␥ n ⫽ (1), the term S/u n ␥ n will vanish for large n, and thus we can conclude F n /u n ␥ n ⱕ K⬘ (and F n /u n ␥ n ⱖ ⫺K⬘) for any constant K⬘ ⬎ K/Q as long as n is large enough. The case ᏻ is proved. The proof of the case o follows the pattern above. Therefore, we only point out the differences. We have to show that for every ⬎ 0 there is some N large enough such that 兩F n 兩/u n ␥ n ⱕ as long as n ⱖ N . Set ⫽ Q 䡠 / 2. Then, by hypothesis, it exists some M such that 兩t n 兩 ⱕ u n for every n ⱖ M . Define G n using u n as toll function for every n ⱖ M , and I n as G n ⫺ /Q 䡠 u n ␥ n for every n ⱖ N ␥ . Then we have I n ⱕ S for some constant S ⬎ 0 and every n large enough, and thus F n /u n ␥ n ⱕ S /u n ␥ n ⫹ /Q. Since the first term vanishes for large n, we can always pick some N large enough to get F n /u n ␥ n ⱕ /Q ⫹ /Q ⫽ for every n ⱖ N (and also F n /u n ␥ n ⱖ ⫺), thus proving the case o and the theorem. e The following lemma provides bounding functions for the most usual toll functions. LEMMA 5.4 —Let u n ⫽ n a ␦ n for every n ⱖ N u , where N u ⱖ 1, a ⬎ 0, and ␦ n is a strictly positive nondecreasing function at every n ⱖ N u . Then ␥ n ⫽ 1 is a bounding function of u n . —Let v n ⫽ lnc n 䡠 ⑀ n for every n ⱖ N v , where N v ⱖ 2, c ⬎ ⫺1, and ⑀ n is a strictly positive nondecreasing function at every n ⱖ N v . Then ␥ n ⫽ ln n is a bounding function of v n . —Let w n ⫽ ln⫺1 n for every n ⱖ N w , for some N w ⱖ 3. Then ␥ n ⫽ ln n 䡠 ln ln n is a bounding function of w n . PROOF. For the first case, let N ␥ ⫽ N u and take  ( z) ⫽ 1 ⫺ z a . Thus,  ( z) ⬎ 0 is nonincreasing in (0, 1). Take any n ⬎ N ␥ and any N ␥ ⱕ k ⬍ n. Then u n ␥ n ⫺ u k ␥ k ⫽ n a ␦ n ⫺ k a ␦ k ⱖ n a ␦ n ⫺ k a ␦ n ⫽ (1 ⫺ (k/n) a )n a ␦ n ⫽  (k/n)u n , and the condition (a) in Definition 5.1 is satisfied. The conditions (b), (c), and (d) are trivial to prove. For the second case, take  ( z) ⫽ ⫺(c ⫹ 1)ln z, if ⫺1 ⬍ c ⱕ 0, or  ( z) ⫽ ⫺ln z, if c ⬎ 0. Let N ␥ ⫽ N v , and take any k and n such that N ␥ ⱕ k ⬍ n. For the moment, we have v n ␥ n ⫺ v k ␥ k ⫽ lnc⫹1 n 䡠 ⑀ n ⫺ lnc⫹1 k 䡠 ⑀ k ⱖ lnc⫹1 n 䡠 ⑀ n ⫺ lnc⫹1 k 䡠 ⑀ n ⫽ (lnc⫹1 n ⫺ lnc⫹1 k) ⑀ n . To check that the condition (a) in Definition 5.1 holds, we consider the last expression separately for positive and negative c. For c ⬎ 0, it is not difficult to prove that lnc⫹1 n ⫺ lnc⫹1 k ⱖ ⫺ln(k/n)lnc n when n ⱖ 1 and 1 ⱕ k ⱕ n. 184 SALVADOR ROURA Therefore, v n ␥ n ⫺ v k ␥ k ⱖ ⫺ln(k/n)lnc n 䡠 ⑀ n ⫽  (k/n)v n . Similarly, when ⫺1 ⬍ c ⱕ 0 it suffices to prove that lnc⫹1 n ⫺ lnc⫹1 k ⱖ ⫺(c ⫹ 1)ln(k/n) lnc n when n ⱖ 1 and 1 ⱕ k ⱕ n, and then v n ␥ n ⫺ v k ␥ k ⱖ ⫺(c ⫹ 1)ln(k/n)lnc n 䡠 ⑀ n ⫽  (k/n)v n . The rest of conditions in Definition 5.1 trivially hold. For the third case, let N ␥ ⫽ N w , and take any n ⬎ N ␥ and any N ␥ ⱕ k ⬍ n. Define  ( z) ⫽ ⫺ln z, and let y ⫽ ln n and z ⫽ k/n. It can be shown that ln y ⫺ ln( y ⫹ ln z) ⱖ ⫺ln z/y for all z in (exp(⫺y), 1]. Therefore, w n ␥ n ⫺ w k ␥ k ⫽ ln ln n ⫺ ln ln k ⫽ ln y ⫺ ln( y ⫹ ln z) ⱖ ⫺ln z/y ⫽  (k/n)w n . The rest of conditions for a bounding function can be easily proved. e The following corollary is an immediate consequence of Theorem 5.3 and Lemma 5.4. COROLLARY 5.5. Let the functions Fn, Gn, and Hn be defined by canonical recursive definitions with toll functions tn ⫽ ᏻ(na␦n), t⬘n ⫽ ᏻ(logc n 䡠 ⑀n) and ᏻ(log⫺1 n), respectively, as stated in Lemma 5.4. Then Fn ⫽ ᏻ(tn), Gn ⫽ ᏻ(t⬘n log n) and Hn ⫽ ᏻ(log log n). Moreover, Fn ⫽ ⌰(tn) if Fn ⱖ 0 and tn ⫽ ᏻ(na␦n). The last theorem of this section allows us to compute the constant factor of the leading term of the solution of some recurrences. THEOREM 5.6. Let Fn be defined by a canonical recursive definition, and let ␥n be a bounding function of tn. Furthermore, assume that Ᏼ(␥) exists. Then Fn ⫽ tn␥n/Ᏼ(␥) ⫹ o(tn␥n). PROOF. From the proof of Theorem 5.3 we know that Ᏼ n( ␥ ) ⫽ ⍀(1). So, if Ᏼ exists, it is strictly positive. Define (␥) Gn ⫽ 冦 Fn , Fn ⫺ 0 ⱕ n ⬍ N␥ if t n␥ n Ᏼ (␥) n ⱖ N␥ . , if For n ⱖ N ␥ , use the definition of G n in both directions, like in the proof of Theorem 5.3. This yields Gn ⫽ tn ⫺ Ᏼ n( ␥ ) Ᏼ (␥) 䡠 tn ⫹ 冘 w n, k G k . 0ⱕk⬍n Let t⬘n denote the toll function above, and let h n ⫽ Ᏼ n( ␥ ) ⫺ Ᏼ ( ␥ ) . Then t⬘n ⫽ t n ⫺ (Ᏼ ( ␥ ) ⫹ h n )/Ᏼ ( ␥ ) 䡠 t n ⫽ ⫺h n t n /Ᏼ ( ␥ ) ⫽ o(t n ), because h n ⫽ o(1). Therefore, it suffices to apply Theorem 5.3 to get G n ⫽ o(t n ␥ n ), which implies F n ⫽ t n ␥ n /Ᏼ ( ␥ ) ⫹ G n ⫽ t n ␥ n /Ᏼ ( ␥ ) ⫹ o(t n ␥ n ). e As an example of application of Theorem 5.6, we can easily compute the expected number of comparisons to find a key chosen at random in a trie with n keys, when the digits are independent and equally likely to be 0 or 1. The recurrence is Tn ⫽ 1 ⫹ 1 2 n 冘 0ⱕkⱕn 冉冊 n T . k k Improved Master Theorems for Divide-and-Conquer Recurrences 185 (It would be a simple matter to write another recurrence with range 0 . . . n ⫺ 1 for k.) Note that this recurrence is not covered by any of the MTs presented in this work; however, we can solve it anyway. The entropy with respect to ln n is Ᏼ n(ln) ⫽ ln n ⫺ 1 2 n 冘 2ⱕkⱕn 冉冊 n ln k. k The distribution of weights gets closer to n/ 2 as long as n grows. This implies Ᏼ n(ln) ⬃ ln n ⫺ ln(n/ 2), Ᏼ(ln) ⫽ ln 2, and T n ⬃ ln n/ln 2 ⫽ log2 n. More formally, we can use the fact that 冉冊 冉 冊 冘 1 2n 2n n ⱕ exp ⫺ k 6 (1⫹)n/ 2⬍kⱕn for any 0 ⱕ ⱕ 1 (see Hagerup and Rub [1990, page 306]), and set ⫽ n ⫽ n ⫺1/3 to get Ᏼ n(ln) ⫽ ln n ⫺ 1 2 ⱖln n ⫺ ln n 冉 冘 2ⱕkⱕ(1⫹n)n/ 2 共 1 ⫹ n兲 n 2 冉冊 冘 冉冊 1 n n ln k ⫺ n ln k k 2 (1⫹n)n/ 2⬍kⱕn k 冊 冉 冊 ⫺ exp ⫺ n2 n 6 ln n ⫽ ln 2 ⫹ o共1兲. On the other hand, it is easy to prove an upper bound ln 2 for Ᏼ(ln). Therefore, Ᏼ(ln) ⫽ ln 2, and finally T n ⬃ log2 n. 6. Proof of the Discrete Master Theorem In this section, we will derive the Discrete MT. While doing this, we will repeatedly make use of the quantities introduced in Definitions 2.1, 4.1 and 4.2. LEMMA 6.1. ⌽( x) is a strictly decreasing continuous function such that limx3⫹⬁ ⌽( x) ⫽ 0 and limx3⫺⬁ ⌽( x) ⫽ ⫹⬁. PROOF. By elementary calculus. LEMMA 6.2. e A discrete recursive definition is canonical if and only if ⌽(0) ⫽ 1. PROOF. For the “only if” proof, we observe that W ⫽ limn3⫹⬁ W n ⫽ 兺 1ⱕdⱕD w d ⫽ ⌽(0). For the “if” proof, the definition of discrete recursive definition tells us that 兩m n 兩 ⫽ 兩W n ⫺ ⌽(0)兩 ⱕ 兺 1ⱕdⱕD 兩r d, n 兩 ⫽ ᏻ(n ⫺ ). Furthermore, Z ⫽ limn3⬁ Z n ⫽ 兺 1ⱕdⱕD w d 䡠 z d ⫽ ⌽(1), which by Lemma 6.1 is strictly smaller than 1 when W ⫽ ⌽(0) ⫽ 1. e Theorem 6.3 justifies the cases 2.3 and 3 of the Discrete MT when the recurrence is canonical, that is, when ␣ ⫽ 0. Note that the case 2.3 reduces to a ⫽ 0 and c ⬍ ⫺1, and the condition Ᏼ ⬍ 0 in the case 3 is equivalent to a ⬍ 0. THEOREM 6.3. Let Cn be defined by a canonical discrete recursive definition, and let tn ⫽ ᏻ(logc n), where c ⬍ ⫺1. Then Cn ⫽ ᏻ(1). Moreover, Cn ⫽ ⌰(1) if Cn ⱖ 0 for every n ⱖ 0 and tn ⬎ 0 for n large enough. 186 SALVADOR ROURA PROOF. It is enough to realize that 兺 0ⱕk⬍N w n, k ⫽ 0 for large n, and use Theorems 4.3 and 4.4. e For the next step, we need to define the concept of subpolynomial function formally. Definition 6.4. Let n be a strictly positive nondecreasing function for large n. Moreover, assume that for every ⬎ 0 the function n / n is increasing as long as n is large enough. Then we say that n is a subpolynomial function. Lemma 6.5 is used to prove Theorems 6.6 and 7.10. LEMMA 6.5. Let tn ⫽ nan, where a ⬎ 0 and n ⫽ n or n ⫽ 1/n for some subpolynomial function n. Then 1 is a bounding function of tn. PROOF. We only need to prove that n a n is as stated by Lemma 5.4, which is obvious when n ⫽ n . When n ⫽ 1/ n , it is enough to express t n as n a/ 2 ␦ n , with ␦ n ⫽ n a/ 2 / n . e Theorem 6.6 corresponds to the case 1 of the Discrete MT when ␣ ⫽ 0 and a ⬎ 0. The statement of the MT applies to toll functions with subpolynomial factors that are ᏻ(logc n) for some c, which is more restrictive than the functions considered by Theorem 6.6. THEOREM 6.6. Let a function be defined by a canonical discrete recursive definition, and let tn ⫽ nan, where a ⬎ 0 and n ⫽ n or n ⫽ 1/n for some subpolynomial function n. Then Ᏼ(1) ⫽ 1 ⫺ ⌽(a). PROOF. Ᏼ (1) n Let us assume n ⫽ n . Then, for large n, ⫽1⫺ 冘 R d, n 䡠 1ⱕdⱕD t S d, n tn ⫽1⫺ 冘 冉 共 w d ⫹ r d, n 兲 z d ⫹ 1ⱕdⱕD s d, n n 冊 a S d, n n . But 1 ⱖ S d, n / n ⱖ (S d, n /n) ⑀ ⫽ ( z d ⫹ s d, n /n) for any 1 ⱕ d ⱕ D and any ⬎ 0, as long as n is large enough. Moreover, the contribution to Ᏼ n(1) of r d, n and s d, n vanishes for large n. Altogether, 1 ⫺ ⌽共a兲 ⫽ 1 ⫺ 冘 1ⱕdⱕD w d 䡠 z da ⱕ Ᏼ (1) ⱕ 1 ⫺ 冘 w d 䡠 z da⫹ ⫽ 1 ⫺ ⌽ 共 a ⫹ 兲 . 1ⱕdⱕD This is true no matter how small is, and ⌽( x) is a continuous function. We can thus conclude Ᏼ (1) ⫽ 1 ⫺ ⌽(a). A similar argument proves the case n ⫽ 1/ n . e Note that the MTs do not deal with toll functions whose growing rate is larger than polynomial, like 2 n . Nevertheless, several of the results in this work also apply to superpolynomial toll functions, which are formally defined as follows: Definition 6.7. Let u n be a positive function for large n. For every a ⬎ 0, assume that u n /n a is increasing as long as n is large enough. Then we say that u n is a superpolynomial function. Notice that the conditions in the first case of Lemma 5.4 trivially hold for any superpolynomial function. As a consequence, the statement of Corollary 5.5 for Improved Master Theorems for Divide-and-Conquer Recurrences 187 toll functions like t n ⫽ ᏻ(n a ␦ n ) is true not only for polynomial toll functions but for superpolynomial toll functions as well. The next theorem deals with discrete recurrences when the toll function is superpolynomial. THEOREM 6.8. Let a function be defined by a canonical discrete recursive definition, and let tn be a superpolynomial function. Then Ᏼ(1) ⫽ 1. PROOF. The proof is very similar to that of Theorem 6.6. It is enough to realize that Ᏼ (1) ⱖ 1 ⫺ ⌽(a) for every a ⬎ 0, no matter how large a is. e We require Lemma 6.9 for the statements of Theorems 6.10 and 7.12. LEMMA 6.9. Let tn ⫽ lnc n 䡠 n, where c ⬎ ⫺1 and n ⫽ n or n ⫽ 1/n for some sublogarithmical function n. Then ln n is a bounding function of tn. PROOF. If n ⫽ n , then t n is clearly as stated by Lemma 5.4. If n ⫽ 1/ n , we only need to write t n as ln(c⫺1)/ 2 n 䡠 ␦ n , with ␦ n ⫽ ln(c⫹1)/ 2 n/ n . e Theorem 6.10 corresponds to the case 2.1 of the Discrete MT when ␣ ⫽ a ⫽ 0. THEOREM 6.10. Let a function be defined by a canonical discrete recursive definition, and let tn ⫽ lnc n 䡠 n, where c ⬎ ⫺1 and n ⫽ n or n ⫽ 1/n for some sublogarithmical function n. Then Ᏼ(ln) ⫽ ⫺(c ⫹ 1)兺1ⱕdⱕD wd 䡠 ln zd. PROOF. Let us assume n ⫽ 1/ n (the case n ⫽ n is similar). Then Ᏼ (ln) n 冘 共w ⫹ r ⫽ ln n ⫺ d d,n 兲 lnc⫹1Sd,n 1ⱕdⱕD lnc n 䡠 n Sd, n for large n. Besides, lnc⫹1Sd,n lnc n ⱕ lnc⫹1Sd,n lnc n 䡠 n Sd, n ⱕ lnc⫹1⫺Sd,n lnc⫺n for any 1 ⱕ d ⱕ D and any ⬎ 0, as long as n is large enough. Furthermore, ln( z d ⫹ s d, n /n) ⫽ ln z d ⫹ ᏻ(n ⫺ ) for some ⬎ 0. Thus, lnc⫹1Sd,n ⫽ 共ln n ⫹ ln zd ⫹ ᏻ共n⫺兲兲c⫹1 ⫽ lnc⫹1n ⫹ 共c ⫹ 1兲lnc n ln zd ⫹ ᏻ共logc⫺1n兲 ⫹ ᏻ共n⫺ logc n兲. Taking into account that ᏻ(logc⫺1 n) ⫹ ᏻ(n ⫺ logc n) ⫽ ᏻ(logc⫺1 n), and that 冘 兩r d, n 兩 䡠 1ⱕdⱕD lnc⫹1Sd,n lnc n ⱕ 冘 兩rd,n兩ln n ⫽ ᏻ共n⫺log n兲, 1ⱕdⱕD we can bound Ᏼ n(ln) as follows: Ᏼ (ln) n ⱕ ln n ⫺ 冘 共w ⫹ r d 1ⱕdⱕD d,n 兲 lnc⫹1Sd,n lnc n 188 SALVADOR ROURA 冘 w 共ln n ⫹ 共c ⫹ 1兲ln z ⫹ ᏻ共log ⫽ ⫺共c ⫹ 1兲 冘 w 䡠 ln z ⫹ ᏻ共log n), ⫽ ln n ⫺ d d ⫺1 n))⫹ᏻ(n⫺log n兲 1ⱕdⱕD d ⫺1 d 1ⱕdⱕD where, for the last step, we have used the fact that W ⫽ 1. A similar reasoning yields the bound Ᏼ n(ln) ⱖ ⫺共c ⫹ 1 ⫺ 兲 冘 wd 䡠 ln zd ⫹ ᏻ共log⫺1n). 1ⱕdⱕD From these last two bounds, and since the one above holds for any ⬎ 0, the theorem is proved. e Finally, Theorem 6.11 corresponds to the case 2.2 of the Discrete MT when ␣ ⫽ a ⫽ 0. THEOREM 6.11. Let a function be defined by a canonical discrete recursive definition, and let tn ⫽ ln⫺1 n. Then Ᏼ(ln 䡠 ln ln) ⫽ ⫺兺1ⱕdⱕD wd 䡠 ln zd. PROOF. By the definitions of entropy and discrete recursive definition, Ᏼ n(ln䡠ln ln) ln n ⫽ ln ln n ⫺ 冘 共w ⫹ r d d,n 1ⱕdⱕD 兲ln ln 冉冉 zd ⫹ sd,n n 冊冊 n , as long as n is large enough. Let y ⫽ ln n. Recall that 兩r d, n 兩 ⫽ ᏻ(n ⫺ ) and 兩s d, n 兩/n ⫽ ᏻ(n ⫺ ). Then, ln) Ᏼ (ln䡠ln y y ⫽ ln y ⫺ 冘 共w ⫹ ᏻ共exp共⫺y兲兲兲ln共 y ⫹ ln共 z ⫹ ᏻ共exp共⫺y兲兲兲兲. d d 1ⱕdⱕD The contributions of the terms ᏻ(exp(⫺ y)) and ᏻ(exp(⫺ y)) vanish for large y. Thus, ln) Ᏼ (ln䡠ln ln) ⫽ lim Ᏼ(ln䡠ln ⫽ lim y y3⫹⬁ y3⫹⬁ 冘 1ⱕdⱕD wd共ln y ⫺ ln共 y ⫹ ln zd兲兲 1/y . Now it suffices to use l’Hôpital’s rule to get the statement of the theorem. e To derive both the Discrete and the Continuous MTs, we will use the fundamental property that every discrete or continuous recursive definition is either canonical or can be reduced to a canonical one by means of a definition like C n ⫽ F n /n ␣ , for some appropriate constant ␣. This concept is formalized as follows: Definition 6.12. Let Ᏺ be a DAC recursive definition of a function F n . We say that Ᏺ is a proper DAC recursive definition if and only if there exists some Improved Master Theorems for Divide-and-Conquer Recurrences constant ␣ such that, if we define C n ⫽ F n /n ␣ , then Cn ⫽ tn n␣ ⫹ 冘 0ⱕk⬍n 189 冉冊 冘 k k␣ Fk tn w n, k 䡠 ␣ 䡠 ␣ ⫽ ␣ ⫹ w n, k n k n n 0ⱕk⬍n ␣ Ck is a canonical recursive definition. For instance, any canonical recursive definition is a proper DAC recursive definition with ␣ ⫽ 0, that is, with C n ⫽ F n . Typically, W ⱖ 1, and then ␣ is positive. For W smaller than 1 (which is not usual in practice) ␣ is negative, which is problematic for small indices. This is why we required W to be at least 1 for continuous recursive definitions; note that the term (k/n) ␣ is unbounded for small k and negative ␣. By contrast, for discrete recursive definitions we allowed W to be smaller than 1; this is a reason to avoid the case z d ⫽ 0. As an example of nonproper DAC recursive definition, we have (7); it is easy to see that it is not canonical nor can be converted into canonical through a change like C n ⫽ F n /n ␣ . Theorems 6.13 and 7.14 state that this is never the case with discrete and continuous recursive definitions. THEOREM 6.13. All discrete recursive definitions are proper DAC recursive definitions whose ␣ is the unique solution of ⌽(␣) ⫽ 1. PROOF. From Lemma 6.1, ⌽(␣) ⫽ 1 has always a unique solution. Define C n ⫽ F n /n ␣ . Then, for large n, Cn ⫽ tn n␣ ⫹ 冘 R⬘d , n C S d, n , 1ⱕdⱕD where R⬘d, n ⫽ (w d ⫹ r d, n )( z d ⫹ s d, n /n) ␣ . Set w⬘d ⫽ w d 䡠 z ␣d and r⬘d, n ⫽ R⬘d, n ⫺ w⬘d . Then we have 兺 1ⱕdⱕD 兩r⬘d, n 兩 ⫽ ᏻ(n ⫺ ⫹ n ⫺ ). Let W n , W, etc. be defined over the new weights. On the one hand, W n ⫽ 兺 1ⱕdⱕD R⬘d, n ⫽ 兺 1ⱕdⱕD (w⬘d ⫹ r⬘d, n ), and W ⫽ 兺 1ⱕdⱕD w⬘d ⫽ ⌽( ␣ ) ⫽ 1. Furthermore, 兩m n 兩 ⫽ 兩W n ⫺ W兩 ⱕ 兺 1ⱕdⱕD 兩r⬘d, n 兩 ⫽ ᏻ(n ⫺ ⫹ n ⫺ ). On the other hand, Zn ⫽ 冘 1ⱕdⱕD 1 R⬘d , n S d, n 䡠 ⫽ Wn n Wn 冘 1ⱕdⱕD 冉 共 w⬘d ⫹ r⬘d , n 兲 z d ⫹ s d, n n 冊 , and hence Z ⫽ 兺 1ⱕdⱕD w⬘d 䡠 z d ⫽ ⌽( ␣ ⫹ 1) ⬍ 1. The theorem follows. e We now make use of Theorems 5.6 and 6.13 to summarize Theorems 6.3, 6.6, 6.8, 6.10, and 6.11 into Corollary 6.14. This corollary also includes the corresponding results for continuous recurrences (Theorems 7.9, 7.10, 7.11, 7.12, and 7.13), which will be presented and proved in Section 7. COROLLARY 6.14. Let Fn be defined by a discrete (respectively, continuous) recursive definition, and let ␣ be the unique solution to ⌽(␣) ⫽ 1 (respectively, (␣) ⫽ 1). —If t n ⫽ ᏻ(n ␣ logc n), where c ⬍ ⫺1, then F n ⫽ ᏻ(n ␣ ). Moreover, F n ⫽ ⌰(n ␣ ) if F n ⱖ 0 for every n ⱖ 0 and t n ⬎ 0 for large n. 190 SALVADOR ROURA —If t n ⫽ n a n , where a ⬎ ␣ and n ⫽ n or n ⫽ 1/ n for some subpolynomial function n , then F n ⬃ t n /(1 ⫺ ⌽(a)) (respectively, F n ⬃ t n /(1 ⫺ (a))). —If t n is a superpolynomial function, then F n ⬃ t n . —If t n ⫽ n ␣ lnc n 䡠 n , where c ⬎ ⫺1 and n ⫽ n or n ⫽ 1/ n for some sublogarithmical function n , then F n ⬃ t n ln n/Ᏼ, where Ᏼ ⫽ ⫺(c ⫹ 1)兺 1ⱕdⱕD w d 䡠 ( z d ) ␣ ln z d (respectively, Ᏼ ⫽ ⫺(c ⫹ 1) 兰 10 ( z) z ␣ ln z dz). —If t n ⫽ n ␣ ln⫺1 n, then F n ⬃ t n ln n 䡠 ln ln n/Ᏼ, where Ᏼ ⫽ ⫺兺 1ⱕdⱕD w d 䡠 ( z d ) ␣ ln z d (respectively, Ᏼ ⫽ ⫺兰 10 ( z) z ␣ ln z dz). 7. Proof of the Continuous Master Theorem We begin with the conjecture included in Definition 3.1. CONJECTURE 7.1. For every positive function ( z) such that 兰10 ( z) dz converges, there exists some ⬍ 0 such that 兰10 ( z) z dz also converges. The author of this paper could not prove that, irrespective of ( z), the integral ( x) converges for every x 僆 [ , 0] for some ⬍ 0, though no counterexample of this statement was found. However, this property clearly holds for the shape functions we usually deal with. For instance, if ( z) is bounded near 0, then any ⬎ ⫺1 fulfills the condition above. To the best of the author’s knowledge, it is an open problem to determine if the statement of Conjecture 7.1 is always true. The following lemma provides an easy way to find the shape function of many continuous recurrences. LEMMA 7.2. Let n,k ⫽ A 䡠 f1 . . . fm/( g1 . . . gm⫹1) be the weights of a given recurrence, where A ⬎ 0 is an arbitrary constant, m ⱖ 0 is any integer constant, fi ⫽ (ain ⫹ bik ⫹ ci) for all 1 ⱕ i ⱕ m for some constants ai, bi, and ci such that at least one of ai or bi is not 0, and gi ⫽ (n ⫹ di) for all 1 ⱕ i ⱕ m ⫹ 1, where the di’s are arbitrary constants. Set n,k ⫽ A 䡠 (a1n ⫹ b1k) . . . (amn ⫹ bmk)/nm⫹1 and ( z) ⫽ n 䡠 n,zn, and suppose that 兰10 ( z) dz is at least 1. Then the given recurrence is continuous and ( z) is its shape function. PROOF. First, we prove that there exists some ⬍ 0 such that 兰 10 ( z) z dz converges. Since ⬘( z) exists and is bounded in [0, 1], ( z) is also bounded in [0, 1]. Set h ⫽ max{ ( z)} 0ⱕzⱕ1 , and choose any ⫺1 ⬍ ⬍ 0. Then 兰 10 ( z) z dz ⱕ h 兰 10 z dz ⬍ ⫹⬁. To prove the conditions in Definition 3.2, let B ⱖ 0 be such that 兩 ⬘( z)兩 ⱕ B for every 0 ⱕ z ⱕ 1. It is easy to see that this bound produces 冕 (k⫹1)/n k/n 共 z 兲 dz ⱕ 冕 冉冉冊 冉 冊冊 (k⫹1)/n k/n k n ⫹ z⫺ k n B dz ⫽ 共 k/n 兲 n ⫹ B 2n 2 , (k⫹1)/n and its symmetric 兰 k/n ( z) dz ⱖ (k/n)/n ⫺ B/ 2n 2 . Now, we set M n ⫽ n 2 to get n, k ⱕ B/ 2n and 兺 0ⱕk⬍n n, k ⫽ ᏻ(n ⫺1 ). Finally, it is enough to notice Improved Master Theorems for Divide-and-Conquer Recurrences that 兩 n, k ⫺ n, k 兩 ⫽ ᏻ(n ⫺2 ) to obtain 冘 0ⱕk⬍n 冘 n, k ⱕ 0ⱕk⬍n 冉冏 冏 冏 n, k ⫺ n, k ⫹ n, k ⫺ 冕 (k⫹1)/n 共 z 兲 dz k/n 冏冊 191 ⫽ ᏻ 共 n ⫺1兲. e Hereafter, we will present results for continuous recurrences that are equivalent to those for discrete recurrences in Section 6, together with some technical propositions. LEMMA 7.3. ( x) is a strictly decreasing continuous function in the interval [, ⫹⬁), such that limx3⫹⬁ ( x) ⫽ 0. PROOF. By hypothesis, (0) ⱖ 1. This implies that there are z 1 and z 2 such that 0 ⬍ z 1 ⬍ z 2 ⬍ 1 and 兰 zz 12 ( z) dz ⬎ 0. For every x ⬍ y such that ( x) and ( y) exist, 共 x兲 ⫺ 共 y兲 ⱖ 冕 z2 共 z 兲共 z x ⫺ z y 兲 dz ⱖ z1 冕 z2 共 z 兲 dz 䡠 min兵 zx ⫺ zy其z1ⱕzⱕz2 ⬎ 0. z1 Hence, ( x) is a strictly decreasing function. Proving that ( x) tends to 0 as long as x grows is not more difficult. For every ⬎ 0, let 0 ⬍ z ⬍ 1 be large enough to get 兰 z1 ( z) dz ⱕ / 2. Assume x ⱖ 0. Then, 共 x兲 ⫽ 冕 z 0 ⱕ 共 z 兲 x 共 z 兲 z x dz ⫹ 冕 冕 冕 1 共 z 兲 z x dz z z 共 z兲 dz ⫹ 1 z 0 共 z兲 dz ⱕ 共 z兲x共0兲 ⫹ ⱕ 2 for x large enough. It is left to prove that ( x) is a continuous function. Recall that ⬍ 0 is the constant such that, according to Conjecture 7.1, 兰 10 ( z) z dz converges. Choose any a such that a ⬎ . Then, lim 兩共 x兲 ⫺ 共a兲兩 ⫽ lim x3a ⱕ x3a 冕 1 0 冏冕 1 0 共 z兲 z共 zx⫺ ⫺ za⫺兲 dz 冏 共 z兲 z dz 䡠 lim共max兵兩zx⫺ ⫺ za⫺兩其0ⱕzⱕ1兲 ⫽ 共兲 䡠 0 ⫽ 0. e x3a The following two technical propositions will be used in several proofs in this section. PROPOSITION 7.4. Let a function be defined by a continuous recursive definition. For every x ⬎ 0, define 192 SALVADOR ROURA n, j 共 x 兲 ⫽ 冏 冘 n, k k僆I n, j 冉冊 冕 x k ⫺ n z n, j⫹1 共 z 兲 z x dz z n, j 冏 for all 0 ⱕ j ⬍ M n . Then for every x ⬎ 0, we have 兺 0ⱕj⬍M n n, j ( x) ⫽ ᏻ(n ⫺ ) for some ⬎ 0. PROOF. First of all, notice that n, j (0) equals n, j . Take any 0 ⱕ j ⬍ M n , and assume that the first term in the definition of n, j ( x) is larger than the second term. Then 冉 冊 冕 冉 冊 冘 冉 冊冕 冘 冉 冊冉 冘 冕 n, j 共 x 兲 ⱕ 冘 n, k z n, j⫹1 䡠 n ⫽ ⫽ n,k ⫺ k僆In, j 共 j ⫹ 1兲x ⫺ jx 共 M n兲 x 共 z 兲共 z n, j 兲 x dz z n, j x Mn z n, j⫹1 ⫺ n k僆I n, j j⫹1 x x j Mn n,k ⫹ k僆In, j zn, j⫹1 共 z兲 dz zn, j x j Mn n,k ⫺ k僆In, j zn, j⫹1 zn, j 冊 共 z兲 dz . Now, if we set n ⫽ 再 1, if x x 共Mn兲 ⫺ 共Mn ⫺ 1兲 , if 0⬍xⱕ1 , x⬎1 then it is easy to see that ( j ⫹ 1) x ⫺ j x ⱕ n . Moreover, j ⬍ M n . Hence, n, j ( x) ⱕ n /(M n ) x 兺 k僆I n, j n, k ⫹ n, j . If the second term in the definition of n, j ( x) is larger than the first one, a similar reasoning yields n, j ( x) ⱕ n /(M n ) x 兰 zz n,n, jj⫹1 ( z) dz ⫹ n, j . Altogether, 冘 n, j 共 x 兲 ⱕ 0ⱕj⬍M n ⫽ 冘 0ⱕj⬍M n n 共 M n兲 x 冉 冘 0ⱕk⬍n 冉 冉 n,k ⫹ n 共 M n兲 x 冕 1 0 冘 n, k ⫹ 冊 冘 k僆I n, j 共 z兲 dz ⫹ 冕 z n, j⫹1 冊 冊 共 z 兲 dz ⫹ n, j z n, j 0ⱕj⬍Mn n,j ⫽ n 共 M n兲 x ⌰ 共 1 兲 ⫹ ᏻ 共 n ⫺兲 . Finally, taking into account that n /(M n ) x ⫽ ᏻ(n ⫺qx ) when 0 ⬍ x ⱕ 1 and n / (M n ) x ⫽ ᏻ(n ⫺q ) when x ⬎ 1, we can bound the expression above by ᏻ(n ⫺ ) for some ⬎ 0 small enough. e PROPOSITION 7.5. Let a function be defined by a continuous recursive definition. Then, for every x ⬎ 0, 兺0ⱕk⬍n n,k(k/n)x ⫽ ( x) ⫹ ᏻ(n⫺) for some ⬎ 0. Improved Master Theorems for Divide-and-Conquer Recurrences PROOF. 冏 冘 0ⱕk⬍n It is enough to observe that n, k 冉冊 冏 冏 冉 x k 冘 ⫺ 共 x兲 ⫽ n 0ⱕj⬍M n 冘 n, k k僆I n, j 冉冊 k n x ⫺ 冕 z n, j⫹1 193 共 z 兲 z x dz z n, j 冊冏 , which is not larger than 兺 0ⱕj⬍M n n, j ( x). But, according to Proposition 7.4, this sum is ᏻ(n ⫺ ) for some ⬎ 0. e A continuous recursive definition is canonical if and only if LEMMA 7.6. (0) ⫽ 1. PROOF. For the “only if” proof, a reasoning similar to the one in Proposition 7.5 yields 兩W n ⫺ (0)兩 ⫽ ᏻ(n ⫺ ). Hence, (0) has to equal 1 for the recurrence to be canonical. For the “if” proof, when (0) ⫽ W ⫽ 1, we have 兩m n 兩 ⫽ ᏻ(n ⫺ ). Moreover, W n Z n ⫽ 兺 0ⱕk⬍n n, k k/n ⫽ (1) ⫹ ᏻ(n ⫺ ) for some ⬎ 0 small enough. Now, taking into account that W n ⫽ 1 ⫹ ᏻ(n ⫺ ), we obtain Z n ⫽ (1) ⫹ ᏻ(n ⫺ ⫹ n ⫺ ), and conclude that Z ⫽ (1) ⬍ 1. e We require just two more technical propositions before proving the main results for continuous recurrences. PROPOSITION 7.7. Let n,k be the weights of a continuous recursive definition, fn be any function such that fn ⫽ ⍀(1) and fn ⫽ o(n), x ⱖ 0, and ⬎ 0 and 0 ⬍ q ⱕ 1 be the constants in the definition of continuous recursive definition. Define hn ⫽ max{ fn, n1⫺q}. Then 兺0ⱕk⬍fn n,k(k/n)x ⫽ ᏻ(max{n⫺, (hn/n)⫺}), where ⬍ 0 is such that () converges. PROOF. Assume x ⫽ 0. Let g n ⫽ ⌰(h n 䡠 n q⫺1 ) be a function with integer values such that g n 䡠 n/M n ⱖ f n for large n (notice that this implies g n ⱖ 1). Then 兺 0ⱕk⬍f n n, k ⱕ 兺 0ⱕk⬍g n 䡠 n/M n n, k ⫽ 兺 0ⱕj⬍g n 兺 k僆I n, j n, k for large n. On the other hand, 冏冘 0ⱕj⬍g n 冉 冘 n, k ⫺ k僆I n, j 冕 z n, j⫹1 z n, j 共 z 兲 dz 冊冏 ⱕ 冘 n, j ⫽ ᏻ 共 n ⫺兲. 0ⱕj⬍g n Furthermore, 兺 0ⱕj⬍g n 兰 zz n,n, jj⫹1 ( z) dz ⫽ 兰 g0n /M n ( z) z z ⫺ dz, which can be bounded by 冉 冊冕 gn Mn ⫺ gn/Mn 共 z兲 z dz ⱕ ᏻ共共hn/n兲⫺兲共兲 ⫽ ᏻ共共hn/n兲⫺兲. 0 Altogether, the proposition is proved for the case x ⫽ 0. The proof for x ⬎ 0 is now trivial, since 兺 0ⱕk⬍f n n, k (k/n) x ⱕ 兺 0ⱕk⬍f n n, k . e PROPOSITION 7.8. Let n,k be the weights of a continuous recursive definition, x ⱖ 0, and N ⱖ 1 be any constant. Then 兺0ⱕk⬍N n,k(k/n)x ⫽ ᏻ(n⫺u) for some u ⬎ 0. 194 SALVADOR ROURA PROOF. It is enough to use Proposition 7.7 with f n ⫽ N. Then h n ⫽ ⌰(n 1⫺q ) and the sum above is bounded by ᏻ(max{n ⫺ , n q }). e THEOREM 7.9. Let Cn be defined by a canonical continuous recursive definition, and let tn ⫽ ᏻ(logc n), where c ⬍ ⫺1. Then Cn ⫽ ᏻ(1). Moreover, Cn ⫽ ⌰(1) if Cn ⱖ 0 for every n ⱖ 0 and tn ⬎ 0 for n large enough. PROOF. By Proposition 7.8, we have 兺 0ⱕk⬍N w n, k ⫽ ᏻ(n ⫺u ) for some u ⬎ 0. Hence, we only need to use Theorems 4.3 and 4.4 to complete this proof. e THEOREM 7.10. Let a function be defined by a canonical continuous recursive definition, and let tn ⫽ nan, where a ⬎ 0 and n ⫽ n or n ⫽ 1/n for some subpolynomial function n. Then Ᏼ(1) ⫽ 1 ⫺ (a). PROOF. Let us assume n ⫽ 1/ n . Then Ᏼ (1) n 冘 ⫽1⫺ n, k 䡠 N ␥ ⱕk⬍n tk tn ⫽1⫺ 冘 n, k N ␥ ⱕk⬍n 冉冊 k n a n k . By hypothesis, for every ⬎ 0 there exists some N such that k / k ⱕ (k ⫹ 1) / k⫹1 and k ⱕ k⫹1 for all k ⱖ N . Choose any 0 ⬍ ⬍ a, and let k and n be such that N ⱕ k ⬍ n. Then we have k / k ⱕ n / n and k ⱕ n . Therefore, 冘 N ⱕk⬍n n, k 冉冊 k n a 冘 ⱕ n, k N ⱕk⬍n 冉冊 k n a n k 冘 ⱕ n, k N ⱕk⬍n Now we can set N ␥ ⫽ N to get 1⫺ 冘 N ␥ ⱕk⬍n n, k 冉冊 k n a ⱖᏴ (1) n ⱖ1⫺ 冘 N ␥ ⱕk⬍n n, k 冉冊 冉冊 k k a⫺ . n a⫺ . n From Propositions 7.5 and 7.8, we deduce 1 ⫺ (a) ⱖ Ᏼ (1) ⱖ 1 ⫺ (a ⫺ ), which is true no matter how small is. Since ( x) is a continuous function, we conclude Ᏼ (1) ⫽ 1 ⫺ (a). A similar argument proves the case n ⫽ n . e THEOREM 7.11. Let a function be defined by a canonical continuous recursive definition, and let tn be a superpolynomial function. Then Ᏼ(1) ⫽ 1. PROOF. The proof is very similar to that of Theorem 7.10. e THEOREM 7.12. Let a function be defined by a canonical continuous recursive definition, and let tn ⫽ lnc n 䡠 n, where c ⬎ ⫺1 and n ⫽ n or n ⫽ 1/n for some sublogarithmical function n. Then Ᏼ(ln) ⫽ ⫺(c ⫹ 1) 兰10 ( z)ln z dz. PROOF. First of all, we must make sure that Ᏼ(ln) exists and is strictly positive. It is easy to prove that ⫺兰 10 ( z) ln z dz, if exists, is strictly greater than 0. Proving that it does not diverge is not more difficult. Let ⬍ 0 be such that () converges, and let 0 ⬍ u ⬍ 1 be such that ⫺ln z ⱕ z in the interval (0, u]. Then, Improved Master Theorems for Divide-and-Conquer Recurrences ⫺ 冕 1 冕 共 z兲ln z dz ⱕ 0 u 共 z兲 z dz ⫺ 冕 1 195 共 z兲ln z dz ⱕ 共兲 ⫺ 共0兲ln u ⬍ ⫹⬁. u 0 Now, assume n ⫽ 1, that is, t n ⫽ lnc n. Then we have 冘 Ᏼ n(ln) ⫽ 共1 ⫺ Wn兲ln n ⫹ Wnln n ⫺ n,k 䡠 lnc⫹1k N␥ⱕk⬍n lnc n . Let g n ⫽ ⌰(n d ) be a function with integer values, where d ⫽ q/ 2. So, we have 0 ⬍ d ⬍ q and 0 ⬍ d ⫹ 1 ⫺ q ⬍ 1. For large n, 冘 Ᏼ n(ln) ⫽ ⫺mnln n ⫹ n,k 䡠 lnc⫹1n ⫺ lnc⫹1k lnc n gn䡠n/Mnⱕk⬍n 冘 ⫹ 冘 n,kln n ⫹ 冉 n,k ln n ⫺ N␥ⱕk⬍gn䡠n/Mn 0ⱕk⬍N␥ lnc⫹1k lnc n 冊 . The term ⫺m n lnn above vanishes because m n ⫽ ᏻ(n ⫺ ). Moreover, the second line above is positive, and can be bounded by (兺 0ⱕk⬍g n 䡠 n/M n n, k ) ln n. Setting f n ⫽ ⌰(n 1⫺q/ 2 ) in Proposition 7.7 proves that this sum also vanishes for large n. The rest of the proof is devoted to find the limit of the term that is left. For every g n ⱕ j ⬍ M n , define ⌬ n, j ⫽ 冏 冘 n, k 䡠 lnc⫹1n ⫺ lnc⫹1k lncn k僆I n, j 冉 冕 ⫺ ⫺共c ⫹ 1兲 zn, j⫹1 共 z兲ln z dz zn, j 冊冏 Assume that the first term above is larger than the second one. Then ⌬ n, j c⫹1 冘 ⱕ n, k 䡠 lnc⫹1n ⫺ lnc⫹1共 zn,j 䡠 n兲 k僆I n, j 冉 ⫽ ⫺ln zn,j ⫹ ᏻ 共c ⫹ 1兲lncn 冉 冊冊 冘 1 log n ⫹ 冕 zn, j⫹1 zn, j n,k ⫹ ln zn,j⫹1 k僆In, j 共 z兲ln zn,j⫹1 dz 冕 zn, j⫹1 共 z兲 dz. zn, j But ⫺ln zn,j 冘 k僆In, j ⫽ ln zn,j 䡠 ⱕ ⫺ln n,k 冉冕 冉冊 gn Mn ⫹ ln zn,j⫹1 冕 zn, j⫹1 共 z兲 dz zn, j zn, j⫹1 共 z兲 dz ⫺ zn, j 䡠 n,j ⫹ ln 冉 冘 n,k k僆In, j gn ⫹ 1 gn 冊冕 冊 冉 zn, j⫹1 zn, j ⫹ ln zn,j⫹1 zn,j 共 z兲 dz. 冊冕 zn, j⫹1 zn, j 共 z兲 dz . 196 SALVADOR ROURA Taking into account the facts that ⫺ln( g n /M n ) ⫽ ⌰(log n q⫺d ) ⫽ ᏻ(log n) and ln(1 ⫹ 1/g n ) ⫽ ⌰(1/g n ) ⫽ ᏻ(n ⫺d ), we have ⌬ n, j c⫹1 ⫽ ᏻ 共 log n兲n,j ⫹ ᏻ共n⫺d兲 冕 zn, j⫹1 共 z兲 dz ⫹ ᏻ zn, j 冉 冊冘 1 log n n,k . k僆In, j If the second term in the definition of ⌬ n, j above is larger than the first one, by means of a similar reasoning, we get ⌬ n, j c⫹1 ⫽ ᏻ 共 log n兲n,j ⫹ ᏻ共n⫺d兲 冘 n,k ⫹ᏻ k僆In, j Thus, we can conclude 冘 冘 ⌬ n, j ⫽ ᏻ 共 log n兲 g n ⱕj⬍M n n,j ⫹ ᏻ gnⱕj⬍Mn 冉 冊冕 1 log n zn, j⫹1 共 z兲 dz. zn, j 冉 冊 冉 冊 1 log n Wn ⫹ ᏻ 1 log n 共0兲, which vanishes for large n, because the sum of n, j ’s is ᏻ(n ⫺ ) for some ⬎ 0. Now we are ready to finish the proof, since 冏 冘 n, k 䡠 lnc⫹1n ⫺ lnc⫹1k lncn g n 䡠n/M n ⱕk⬍n 冉 冕 ⫺ ⫺共c ⫹ 1兲 1 共 z兲 ln z dz gn/Mn 冊冏 is bounded by above by 兺 g n ⱕj⬍M n ⌬ n, j ⫽ o(1). Therefore, Ᏼ (ln) ⫽ lim ⫺共c ⫹ 1兲 n3⫹⬁ 冕 1 共 z兲 ln z dz ⫽ ⫺共c ⫹ 1兲 gn/Mn 冕 1 共 z兲 ln z dz. 0 This ends the proof of the case n ⫽ 1. The cases n ⫽ n and n ⫽ 1/ n for sublogarithmical n ⫽ (1) can be proved by similar arguments (see the proof of Theorem 6.10). e THEOREM 7.13. Let a function be defined by a canonical continuous recursive definition, and let tn ⫽ ln⫺1 n. Then Ᏼ(ln 䡠 ln ln) ⫽ ⫺兰10 ( z)ln z dz. PROOF. This proof follows the same pattern as the one of Theorem 7.12. Therefore, we skip some steps, for the sake of brevity. Let n ⫽ exp( 公ln n), and g n ⫽ ⌰(n q / n ) be a function with integer values. By the definitions of entropy and continuous recursive definition, Ᏼ n(ln䡠ln ln) ⫽ ⫺mn ln n 䡠 ln ln n ⫹ ln n 䡠 ⫹ ln n 䡠 ln ln n 冘 0ⱕk⬍N␥ 冘 n,k共ln ln n ⫺ ln ln k兲 gn䡠n/Mnⱕk⬍n n,k ⫹ ln n 䡠 冘 n,k共ln ln n ⫺ ln ln k兲, N␥ⱕk⬍gn䡠n/Mn as long as n is large enough. The term ⫺m n ln n 䡠 ln ln n clearly vanishes for large n. Moreover, the second line above is positive, and bounded by (兺 0ⱕk⬍g n 䡠 n/M n n, k ) ln n ln ln n. By Proposition 7.7, this term is also o(1), since Improved Master Theorems for Divide-and-Conquer Recurrences 197 f n ⫽ h n ⫽ n/ n and (h n /n) ⫺ ⫽ n . Below, we prove that the limit of the remaining term above is as stated by the theorem. For every g n ⱕ j ⬍ M n , define 冏 ⌬ n, j ⫽ ln n 䡠 冘 n,k 冉 共ln ln n ⫺ ln ln k兲 ⫺ ⫺ k僆In, j 冕 zn, j⫹1 共 z兲ln z dz zn, j 冊冏 . Assume that the first term above is larger than the second one (the opposite produces a similar bound). Then ⌬ n, j ⱕ ln n 䡠 冘 n,k 共ln ln n ⫺ ln ln共 zn,j 䡠 n兲兲 ⫹ k僆In, j 冕 zn, j⫹1 共 z兲ln zn,j⫹1 dz. zn, j Now it is not difficult to get 冉 ln共1/zn,j兲 ⌬ n, j ⱕ ⫺ln n 䡠 ln 1 ⫺ ln n 冉 冊冕 1 ⫹ln 1 ⫹ gn zn, j⫹1 冊冘 n,k ⫹ ln zn,j k僆In, j 冕 zn, j⫹1 共 z兲 dz zn, j 共 z兲 dz. zn, j The contribution to the entropy of the second line is asymptotically irrelevant, because ln(1 ⫹ 1/g n ) ⫽ ⌰(1/g n ) ⫽ o(1). For the next step, we show that the factor ln n 䡠 ln (1 ⫺ ln(1/z n, j )/ln n) equals ln z n, j ⫹ o(1), which is easy if we take into account the fact that 1/z n, j ⫽ ᏻ(M n /g n ) ⫽ ᏻ( n ). Hence, ln(1/z n, j ) ⫽ ᏻ(ln n ) ⫽ ᏻ共 3 ln n兲, which implies ln(1/z n, j )/ln n ⫽ ᏻ(ln⫺2/3 n) ⫽ o(1). Finally, we observe that ln(1 ⫺ x) ⫽ ⫺x ⫹ ᏻ( x 2 ) when x ⫽ o(1) to conclude 冑 冉 ln n 䡠 ln 1 ⫺ ln共1/zn,j兲 ln n 冊 ⫽ ln n 䡠 冉 ln zn,j ln n 冊 ⫹ ᏻ共ln⫺4/3n兲 ⫽ ln zn,j ⫹ o共1兲. Now it is enough to follow the last steps in the proof of Theorem 7.12 to finish this proof. e THEOREM 7.14. All continuous recursive definitions are proper DAC recursive definitions whose ␣ is the unique solution of (␣) ⫽ 1. PROOF. From Lemma 7.3 and (0) ⱖ 1, the equation above has a unique solution. Define C n ⫽ F n /n ␣ . Then, for every n ⱖ N, Cn ⫽ tn 1 n n␣ ⫹ ␣ 冘 n, k F k ⫹ 冘 n, k 䡠 Nⱕk⬍n 0ⱕk⬍N 冘 k␣ Fk 䡠 ⫽ t⬘n ⫹ ⬘n , k C k , n␣ k␣ 0ⱕk⬍n where t⬘n ⫽ t n /n ␣ ⫹ (1/n ␣ )兺 0ⱕk⬍N n, k F k , and ⬘n , k ⫽ 再 0, if ␣ n,k共k/n兲 , if 0ⱕk⬍N N ⱕ k ⬍ n. 198 SALVADOR ROURA From Propositions 7.4 and 7.8, it is a simple matter to prove that ( z) z ␣ is the shape function of Ꮿ (just set x ⫽ ␣ ). Moreover, since (␣) ⫽ 1, we have 兰 10 ( z) z ␣ dz ⫽ 1. This proves that the recurrence for C n is a canonical continuous recursive definition. As a final remark, notice that the term (1/n ␣ ) 兺 0ⱕk⬍N n, k F k in t⬘n is ᏻ(n ⫺ ␣ ⫺u ) for some u ⬎ 0 (use Proposition 7.8), and hence we are allowed to forget about the contribution of this term to the main term of C n . e 8. Computing the Variance We have devoted previous sections to analyze the (expected) cost of algorithms. However, if the executions are random (in the different possible inputs of the same size; or in the different possible executions with the same input, if the algorithm is randomized), then the variance of the cost is also a valuable measure. In this section, we will analyze the variance of two types of algorithms. 8.1. ONE-BRANCH ALGORITHMS. The first class includes the algorithms that perform one recursive call with probability 1 ⫺ S n , and otherwise stop the recursion chain with probability S n , where S n tends to zero as long as n grows. FIND is a prototypical example of this class. It divides the original array into two parts, and afterwards recursively continues in the subarray to the left or in the subarray to the right of the current pivot, or either stops with probability 1/n. In this setting, n, k is the probability that the algorithm performs the recursive call over a subproblem with size k when the original problem has size n. Let ᐀ n be the random variable that describes the nonrecursive cost, including both the cost to split the problem and the cost to combine the recursive solutions. We assume that these two costs do not depend on the particular input nor the recursive solutions, but eventually depend on which was the “pivot” (whatever it means depending on the algorithm). We also assume that the following symmetry holds: (k) T n, j ⫽ Pr兵᐀n ⫽ j兩the 共k ⫹ 1兲-th element is the pivot其 ⫽ Pr兵᐀n ⫽ j兩the 共n ⫺ k兲-th element is the pivot其. Under this hypothesis, the size of the recursive call implicitly gives us which was the pivot (or its symmetric). Let the total cost of the algorithm be described by the random variable Ᏺ n , and let P n, j ⫽ Pr{Ᏺ n ⫽ j}. Of course, we have 兺 jⱖ0 P n, j ⫽ 1. The P n, j ’s satisfy the following recurrence: P n, j ⯝ 冘 0ⱕk⬍n n, k 冘P k, i (k) T n, j⫺i . iⱖ0 The reason for the “⯝” above is that we dismiss the contribution to the cost of the executions that stop the chain of recursive calls, since, by hypothesis, S n tends to zero, and in most practical situations this cost is asymptotically irrelevant. Let E 共 n, k 兲 ⫽ E关᐀n兩the 共k ⫹ 1兲-th element is the pivot兴 ⫽ 冘T jⱖ0 (k) n,j 䡠 j, (14) Improved Master Theorems for Divide-and-Conquer Recurrences and Q 共 n, k 兲 ⫽ E关共᐀n兲2兩the 共k ⫹ 1兲-th element is the pivot兴 ⫽ 199 冘T (k) n,j 䡠 j 2. (15) jⱖ0 Define F n ⫽ E[Ᏺ n ] ⫽ 兺 jⱖ0 P n, j 䡠 j and G n ⫽ E[(Ᏺ n ) 2 ] ⫽ 兺 jⱖ0 P n, j 䡠 j 2 . On the one hand, by means of simple rewriting we obtain Fn ⯝ tn ⫹ 冘 n, k F k , (16) 0ⱕk⬍n as expected. Recall that, despite the approximation above, the main term of the solution of the recurrence is indeed the main term of F n . On the other hand, from the equality j 2 ⫽ ( j ⫺ i) 2 ⫹ 2( j ⫺ i)i ⫹ i 2 , it is straightforward to get Gn ⯝ 冘 n, k 冘 n,k共Q共n, k兲 ⫹ 2E共n, k兲 Fk兲 ⫹ k, i iⱖ0 0ⱕk⬍n ⫽ 冘P 冘T (k) n, j⫺i 䡠 j2 jⱖ0 0ⱕk⬍n 冘 n,kGk . (17) 0ⱕk⬍n To solve this recurrence we need to estimate the sums 兺 k n, k Q(n, k) and 兺 k n, k E(n, k) F k . Assume that the set of n, k ’s corresponds to a canonical continuous recursive definition, and that ᐀ n is not random, that is, ᐀ n ⫽ t n . Then Q(n, k) ⫽ (t n ) 2 , and from E(n, k) ⫽ t n and (16) we have 兺 0ⱕk⬍n n, k 2E(n, k) F k ⯝ 2t n F n ⫺ 2(t n ) 2 . Thus, (17) reduces to G n ⯝ 2t n F n ⫺ 共 t n 兲 2 ⫹ 冘 n, k G k . (18) 0ⱕk⬍n Notice that this recurrence is a continuous recursive definition with the same shape function as (16). Suppose first t n ⬃ n a n , where a ⬎ 0 and n includes subpolynomial terms. According to the Continuous MT, F n ⬃ t n /(1 ⫺ (a)). Therefore, the toll function in (18) is ⬃ 2n 2a ( n ) 2 /(1 ⫺ (a)) ⫺ n 2a ( n ) 2 ⫽ n 2a ( n ) 2 (1 ⫹ (a))/(1 ⫺ (a)), and Gn ⬃ 1 ⫹ 共a兲 共 1 ⫺ 共 2a 兲兲共 1 ⫺ 共 a 兲兲 䡠 共 t n兲 2 . Hence, the variance of Ᏺ n , V[Ᏺ n ] ⫽ E[(Ᏺ n ) 2 ] ⫺ E[Ᏺ n ] 2 , can be computed as V 关 Ᏺ n兴 ⬃ 共2a兲 ⫺ 共a兲2 共1 ⫺ 共2a兲兲共1 ⫺ 共a兲兲2 䡠 共 t n兲 2 . Suppose now t n ⬃ lnc n 䡠 n , where c ⬎ ⫺1 and n includes sublogarithmical terms. Then F n ⬃ t n ln n/(c ⫹ 1)I, where I ⫽ ⫺兰 10 ( z) ln z dz. Replacing this result in (18) yields Gn ⬃ (tn)2 ln2 n/(c ⫹ 1)2I2, and we can only conclude V[Ᏺn] ⫽ o(Fn)2, but no more precise statement can be made in general. 200 SALVADOR ROURA 8.2. TWO-BRANCH ALGORITHMS. These algorithms perform two recursive calls to subproblems with size k and n ⫺ 1 ⫺ k, respectively, with probability 1 ⫺ S n . Otherwise, the algorithm makes no recursive call. Again, S n tends to zero as long as n grows. Quicksort is a prototypical example of this class. It divides the array into two parts, and afterwards it recursively sorts the left and the right subarrays. Let n, k be the probability that the original problem of size n is broken into two subproblems of sizes k and n ⫺ 1 ⫺ k, respectively. Like for one-branch algorithms, assume that the algorithm’s cost to break and recombine does not depend on the particular input nor the recursive solutions, but does depend on k, the “pivot.” Again, let P n, j ⫽ Pr{Ᏺ n ⫽ j}. Then P n, j ⯝ 冘 n, k 冘 P k, i P n⫺1⫺k, y T n, k, j⫺i⫺y . i, yⱖ0 0ⱕk⬍n Let E(n, k) be defined as in (14), and let F n ⫽ E[Ᏺ n ]. It is easy to see that F n follows the recurrence Fn ⯝ tn ⫹ 冘 n, k 共 F k ⫹ F n⫺1⫺k 兲 . 0ⱕk⬍n Let Q(n, k) be defined as in (15), and let G n ⫽ E[(Ᏺ n ) 2 ]. Then 冘 Gn ⯝ n, k 冘 P k, i P n⫺1⫺k, y i, yⱖ0 0ⱕk⬍n 冘T n, k, j⫺i⫺y 䡠 j 2. jⱖ0 Using j 2 ⫽ ( j ⫺ i ⫺ y) 2 ⫹ 2( j ⫺ i ⫺ y)i ⫹ 2( j ⫺ i ⫺ y) y ⫹ 2iy ⫹ i 2 ⫹ y 2 yields Gn ⯝ 冘 n, k 共 Q 共 n, k 兲 ⫹ 2E 共 n, k 兲共 F k ⫹ F n⫺1⫺k 兲 ⫹ 2F k F n⫺1⫺k 兲 0ⱕk⬍n ⫹ 冘 n,k共Gk ⫹ Gn⫺1⫺k兲. 0ⱕk⬍n We can solve the recurrences for F n and G n under some particular hypotheses. Assume that E(n, k) ⫽ t n , Q(n, k) ⫽ (t n ) 2 , and that there exists some function ( z) such that 冘 0ⱕj⬍M n 冏冘 n, k ⫺ k僆I n, j 冕 z n, j⫹1 冏 共 z 兲 dz ⫽ ᏻ 共 n ⫺兲, z n, j where ( z), M n , I n, j , z n, j and are like in Definition 3.2. Then F n follows the continuous recurrence Fn ⯝ tn ⫹ 冘 n, k F k , 0ⱕk⬍n where n, k ⫽ n, k ⫹ n, n⫺1⫺k , and thus ( z) ⫽ ( z) ⫹ (1 ⫺ z). Moreover, ␣ ⫽ 1, because Improved Master Theorems for Divide-and-Conquer Recurrences 冕 1 共 z 兲 z 1 dz ⫽ 0 冕 1 冕 共 共 z 兲 z ⫹ 共 z 兲共 1 ⫺ z 兲兲 dz ⫽ 0 1 201 共 z 兲 dz ⫽ 1. 0 Also, under the assumptions above, we have G n ⯝ 2t n F n ⫺ 共 t n 兲 2 ⫹ 2 冘 冘 n, k F k F n⫺1⫺k ⫹ 0ⱕk⬍n n, k G k . 0ⱕk⬍n Suppose first t n ⬃ n a n , where a ⬎ 1 and n includes subpolynomial terms. Then F n ⬃ t n /(1 ⫺ (a)), and Gn ⬃ 冉 1 ⫹ 共a兲 共 1 ⫺ 共 2a 兲兲共 1 ⫺ 共 a 兲兲 ⫹ 2兰 10 共 z 兲 z a 共 1 ⫺ z 兲 a dz 共 1 ⫺ 共 2a 兲兲共 1 ⫺ 共 a 兲兲 2 冊 共 t n兲 2 , where the integral above results from a reasoning similar to those used to derive the Continuous MT. We can conclude V 关 Ᏺ n兴 ⬃ 共2a兲 ⫺ 共a兲2 ⫹ 2兰10 共 z兲 za共1 ⫺ z兲a dz 共1 ⫺ 共2a兲兲共1 ⫺ 共a兲兲2 䡠 共 t n兲 2 . Suppose now t n ⬃ n lnc n 䡠 n , where c ⬎ ⫺1 and n includes sublogarithmical terms. Then F n ⬃ t n ln n/Ᏼ, where Ᏼ ⫽ ⫺(c ⫹ 1) 兰 10 ( z) z ln z dz. Like for one-branch algorithms, we can only conclude V[Ᏺ n ] ⫽ o(F n ) 2 , since Gn ⬃ 2 兰 10 共 z 兲 z 共 1 ⫺ z 兲 dz 共 1 ⫺ 共 2 兲兲 Ᏼ 2 䡠 共 t n 兲 2 ln2n ⫽ 共tn兲2 ln2n Ᏼ2 . For this last step, it is enough to notice that 2 兰 10 ( z) z(1 ⫺ z) dz ⫽ 1 ⫺ (2). 9. Open Problems The results of this work could be extended in other directions. For instance, consider the system of equations F n(1) F n(2) ⫽ ⫽ t n(1) ⫹ ⫽ (1, 1) (1) n, ⫹···⫹ i Fi 0ⱕi⬍n t (2) n ⫹ t n(k) ⫹ 冘 0ⱕi⬍n 冘 冘 (1, k) (k) n, i Fi , 0ⱕi⬍n (2, 1) n, i F (1) i ⫹···⫹ 0ⱕi⬍n ··· F n(k) 冘 冘 (2, k) (k) n, i Fi , 0ⱕi⬍n (k, 1) (1) n, ⫹···⫹ i Fi 冘 (k, k) (k) n, i Fi , 0ⱕi⬍n where the weights above fulfill the discrete and/or the continuous pattern. The problem is: Can we systematically solve such a system, for a wide set of toll functions and weight distributions? On the other hand, it would be interesting to dispose of theorems to systematically solve recurrences on more than one variable, like 202 SALVADOR ROURA F n, m ⫽ t n, m ⫹ 冘 冘 w n, m, i, j F i, j , 0ⱕi⬍n 0ⱕi⬍n where the weights above follow a discrete or continuous pattern. Finally, and mostly of theoretical interest, we could deal with toll functions t n ⫽ n ␣ ␦ n for some ␦ n subpolynomial and superlogarithmical (like ␦ n ⫽ exp(公ln n)), or ␦ n ⫽ (log⫺1 n) and ␦ n ⫽ o(log⫺1⫹ n) for every ⬎ 0, or ␦ n ⫽ o(log⫺1 n) and ␦ n ⫽ (log⫺1⫺ n) for every ⬎ 0. The main interest of the later case would be finding the maximum growing order for ␦ n such that F n ⫽ ᏻ(n ␣ ). Appendixes A. Examples of the Use of the Discrete Master Theorem We start solving (1). First, we identify the main term of toll function, and the sets of values {w d } 1ⱕdⱕD and { z d } 1ⱕdⱕD . This yields t n ⬃ n 1 ln0 n, w 1 ⫽ w 2 ⫽ 1 and z 1 ⫽ z 2 ⫽ 1/ 2. Note that the bounds for r d, n and s d, n trivially hold here, because Definition 2.1 always covers floors and ceilings. We now define ⌽( x) ⫽ 2(1/ 2) x , and evaluate Ᏼ ⫽ 1 ⫺ ⌽(1) ⫽ 0. Since Ᏼ ⫽ 0, we compute Ᏼ⬘ ⫽ ⫺(0 ⫹ 1)(2(1/2)1 ln(1/2)) ⫽ ln 2. Therefore, M n ⬃ n ln n/ln 2 ⫽ n log2 n. Let us analyze (2). The main term in its toll function is n 0 ln0 n. Moreover, w 1 ⫽ w 2 ⫽ 1/ 2 and z 1 ⫽ z 2 ⫽ 1/ 2. So, we define ⌽( x) ⫽ (1/ 2) x . Since Ᏼ ⫽ 1 ⫺ ⌽(0) ⫽ 0, we compute Ᏼ⬘ ⫽ ⫺(0 ⫹ 1)((1/2)0 ln(1/2)) ⫽ ln 2, and conclude B n ⬃ ln n/ln 2 ⫽ log2 n. We now consider (3). Suppose t n ⫽ 6n 2 /ln5 n. The weights are w 1 ⫽ 2, w 2 ⫽ 4 and w 3 ⫽ 1/ 2; the fractions are z 1 ⫽ 1/3, z 2 ⫽ 1/ 2 and z 3 ⫽ 4/5. It is a simple matter to check that this recurrence follows Definition 2.1. So, we define ⌽( x) ⫽ 2(1/3) x ⫹ 4(1/ 2) x ⫹ 1/ 2 䡠 (4/5) x , and Ᏼ ⫽ 1 ⫺ ⌽(2) ⫽ ⫺122/225. Since Ᏼ ⬍ 0, we have F n ⫽ ⌰(n ␣ ), where ␣ is the unique solution of the equation ⌽(␣) ⫽ 1, which numerically is ␣ ⯝ 2.68723. Solving f 共 n 兲 ⫽ ⌰ 共 n 兲 ⫹ 2f 冉冊 冉冊 冉冊 n 2 ⫹ 2f n 3 ⫹ 2f n 6 is very similar. It yields f(n) ⫽ ⌰(n ␣ ), where ␣ ⯝ 1.72121 is the unique solution of 2(1/2)␣ ⫹ 2(1/3)␣ ⫹ 2(1/6)␣ ⫽ 1. This is an upper bound to the system of equations presented in Kuo and Chang [1994, pp. 79 – 80], where a very good approximation, ␣ ⯝ 1.722, is given.4 Finally, set t n ⫽ n 2 for (11). Solving it is very easy: w 1 ⫽ 1 and z 1 ⫽ 1/4; ⌽( x) ⫽ (1/4) x and Ᏼ ⫽ 1 ⫺ ⌽(2) ⫽ 15/16; since Ᏼ ⬎ 0, we deduce F n ⬃ n 2 /(15/16) ⫽ 16n 2 /15. In this example, we can get more information by means of a simple trick. Let G n ⫽ F n ⫺ 16n 2 /15. Then, 4 Thanks are due to Fatos Xhafa for suggesting this example. Improved Master Theorems for Divide-and-Conquer Recurrences 2 G n ⫽ n ⫹ F n/4 ⫺ 16n 2 15 ⫽⫺ n2 15 ⫹ 16 n 203 2 15 4 ⫹ Gn/4 . We can now find bounds for G n . Taking into account that n/4 ⫺ 3/4 ⱕ n/4 ⱕ n/4, we have n 2 /16 ⫺ 3n/8 ⫹ 9/16 ⱕ n/4 2 ⱕ n 2 /16, and hence ⫺ 2n 5 ⫹ 9 15 ⫹ Gn/4 ⱕ Gn ⱕ Gn/4 . We can use the Discrete MT again to solve G⬘n ⫽ ⫺2n/5 ⫹ 9/15 ⫹ G⬘n/4 . This is even simpler, since the distribution of weights remains unchanged, and so does ⌽( x). The main term in the toll function is negative (⫺2n/5); recall that this is not a problem. Computing Ᏼ yields Ᏼ ⫽ 1 ⫺ ⌽(1) ⫽ 3/4, and therefore G⬘n ⬃ ⫺2/5 䡠 n/(3/4) ⫽ ⫺8n/15. We now solve G ⬙n ⫽ G ⬙n/4 , and get G ⬙n ⫽ ᏻ(n ␣ ) ⫽ ᏻ(1); not ⌰(1), since every term could be zero. Finally, we conclude F n ⫽ 16n 2 /15 ⫹ G n , where ⫺8n/15 ⫹ o(n) ⱕ G n ⱕ ᏻ(1), thus achieving tighter bounds for F n . We will see that for stochastic recurrences this technique provides more accurate results. B. Examples of the Use of the Continuous Master Theorem We first analyze (4). It is trivial to show that ( z) ⫽ 2. Therefore, ( x) ⫽ 兰 10 ( z) z x dz ⫽ 2/( x ⫹ 1) if x ⬎ ⫺1 (and ( x) ⫽ ⫹⬁ otherwise). Since Ᏼ ⫽ 1 ⫺ (1) ⫽ 0, we define Ᏼ⬘ ⫽ ⫺兰 10 ( z) z 1 ln z dz ⫽ 1/ 2, and finally Q n ⬃ n ln n/(1/ 2) ⫽ (2 ln 2)n log2 n ⯝ 1.38n log2 n. To solve (5) we start identifying the shape function for the weights, using Lemma 7.2. First, we replace the term n ⫹ 1 in the denominator of n, k by n. This yields n, k ⫽ 4(n ⫺ k)/n 2 . Second, we compute ( z) ⫽ n 䡠 n, zn ⫽ n 䡠 4(n ⫺ zn)/n 2 ⫽ 4(1 ⫺ z). Third and last, we check that 兰 10 ( z) dz ⫽ 2 ⱖ 1 indeed. Now we define ( x) ⫽ 4 兰 10 (1 ⫺ z) z x dz ⫽ 4(1/( x ⫹ 1) ⫺ 1/( x ⫹ 2)) if x ⬎ ⫺1 (and ( x) ⫽ ⫹⬁ otherwise). Since Ᏼ ⫽ 1 ⫺ (0) ⫽ ⫺1 ⬍ 0, we conclude F n ⫽ ⌰(n ␣ ), where ␣ is the unique solution of (␣) ⫽ 1. This yields ␣ ⫽ (公17 ⫺ 3)/2 ⯝ 0.56155 (the only solution to ␣2 ⫹ 3␣ ⫺ 2 ⫽ 0 that is larger than ⫺1). We now solve (9), for which we already know that ( z) ⫽ 2z. In this case ( x) ⫽ 2/( x ⫹ 2) if x ⬎ ⫺2 (and ( x) ⫽ ⫹⬁ otherwise). Since Ᏼ ⫽ 1 ⫺ (1) ⫽ 1/3 ⬎ 0, it follows that S n ⬃ n/(1/3) ⫽ 3n. In this example, we can get more information, using the technique that was presented in Appendix A. Define G n ⫽ S n ⫺ 3n. Then, Gn ⫽ n ⫹ 1 ⫹ 2 n 2 冘 kS k ⫺ 3n ⫽ ⫺2n ⫹ 1 ⫹ 0ⱕk⬍n 6 n 2 0ⱕk⬍n But 兺 0ⱕk⬍n k 2 ⫽ n 3 /3 ⫺ n 2 / 2 ⫹ n/6. Thus, G n ⫽ ⫺2 ⫹ 1 n ⫹ 2 冘 n2 0ⱕk⬍n 冘 kGk . k2 ⫹ 2 冘 n2 0ⱕk⬍n kGk . 204 SALVADOR ROURA Notice that, in contrast to what happens with discrete recurrences, the recurrence for G n above does not contain noise terms. Now we use the Continuous MT again. The first step is already done, since the distribution of weights remains the same, and ( x) too. Since Ᏼ ⫽ 1 ⫺ (0) ⫽ 0, we compute Ᏼ⬘ ⫽ ⫺兰 10 ( z) z 0 ln z dz ⫽ 1/ 2, and get G n ⬃ ⫺2 ln n/(1/ 2) ⫽ ⫺4 ln n. We can go one step further, defining I n ⫽ G n ⫹ 4H n , which is slightly simpler than defining I n ⫽ G n ⫹ 4 ln n. Notice that we are extracting the main terms of S n one by one. This step yields In ⫽ 4H n n ⫺ 1 n ⫹ 冘 2 n2 kI k , 0ⱕk⬍n where we have used the fact that 兺 0ⱕk⬍n kH k ⫽ n 2 H n / 2 ⫺ n 2 /4 ⫺ nH n / 2 ⫹ n/4. Now we get Ᏼ ⫽ 1 ⫺ (⫺1) ⫽ ⫺1 ⬍ 0, and hence I n ⫽ ᏻ(n ␣ ) ⫽ ᏻ(1); we cannot deduce I n ⫽ ⌰(1), since the toll function in the definition of I n includes positive and negative terms together. At this point we cannot go any further, because we have reached the core of the recurrence. As a conclusion, we have S n ⫽ 3n ⫺ 4 ln n ⫹ ᏻ(1). As a final remark, hybrid recurrences like F n ⫽ n 2 ⫹ F n/ 2 ⫹ 1 n 冘 Fk 0ⱕk⬍n can be analyzed by combining both MTs. So, to solve this recurrence is enough to find out that w 1 ⫽ 1, z 1 ⫽ 1/ 2 and ( z) ⫽ 1; compute Ᏼ ⫽ 1 ⫺ (1/ 2) 2 ⫺ 兰 10 z 2 dz ⫽ 5/12 ⬎ 0; and conclude F n ⬃ n 2 /(5/12) ⫽ 12n 2 /5. ACKNOWLEDGMENTS. I thank my advisor Conrado Martı́nez for his support while working on this problem, and several referees for their helpful comments. REFERENCES AHO, A. V., HOPCROFT, J. E., AND ULLMAN, J. D. 1974. The Design and Analysis of Computer Algorithms. Addison-Wesley, Reading, Mass. BENTLEY, J. L., HAKEN, D., AND SAXE, J. B. 1980. A general method for solving divide-andconquer recurrences. SIGACT News 12, 3, 36 – 44. CORMEN, T. H., LEISERSON, C. E., AND RIVEST, R. L. 1990. Introduction to Algorithms. The MIT Press, Cambridge, Mass. FLAJOLET, P., AND GOLIN, M. 1994. Mellin transforms and asymptotics. Acta Inf. 31, 673– 696. FLAJOLET, P., GONNET, G., PUECH, C., AND ROBSON, J. M. 1993. Analytic variations on quadtrees. Algorithmica 10, 473–500. HAGERUP, T., AND RUB, C. 1990. A guided tour of chernoff bounds. Inf. Proc. Lett. 33, 305–308. HOARE, C. A. R. 1961. FIND (Algorithm 65). Commun. ACM 4, 321–322. HOARE, C. A. R. 1962. Quicksort. Computer J. 5, 10 –15. KAO, M. 1997. Multiple-size divide-and-conquer recurrences. SIGACT News 28, 2 (June), 67– 69. KARP, R. M. 1994. Probabilistic recurrence relations. J. ACM 41, 6 (Nov.), 1136 –1150. KUO, D., AND CHANG, G. J. 1994. The profile minimization problem in trees. SIAM J. Comput. 23, 1 (Feb.), 71– 81. MARTı́NEZ, C., AND ROURA, S. 1998. Optimal sample sizes for quicksort and quickselect. Tech. Rep. LSI-98-1-R. Departament de Llenguatges i Sistemes Informàtics, Universitat Politècnica de Catalunya, Catalonia, Spain. ROURA, S. 1997a. Divide-and-conquer algorithms and data structures. Ph.D. dissertation. Departament de Llenguatges i Sistemes Informàtics, Universitat Politècnica de Catalunya, Catalonia, Spain. Improved Master Theorems for Divide-and-Conquer Recurrences 205 ROURA, S. 1997b. An improved master theorem for divide-and-conquer recurrences. In Proceedings of the 24th International Colloquium (ICALP ’97). Pierpaolo Degano, Roberto Gorrieri, and Alberto Marchetti-Spaccamela, Eds. Lecture Notes in Computer Science, vol. 1256. SpringerVerlag, New York, pp. 449 – 459. SEDGEWICK, R., AND FLAJOLET, P. 1996. An Introduction to the Analysis of Algorithms. AddisonWesley, Reading, Mass. VERMA, R. M. 1994. A general method and a master theorem for divide-and-conquer recurrences with applications. J. Algorithms 16, 67–79. VERMA, R. M. 1997. General techniques for analyzing recursive algorithms with applications. SIAM J. Comput. 26, 568 –581. WANG, X., AND FU, Q. 1996. A frame for divide-and-conquer recurrences. Inf. Proc. Lett. 59, 45–51. RECEIVED JULY 1998; REVISED JULY 2000; ACCEPTED JULY 2000 Journal of the ACM, Vol. 48, No. 2, March 2001.
© Copyright 2026 Paperzz