• 沒有找到結果。

The proof for exact powers

在文檔中 ALGORITHMS INTRODUCTION TO (頁 119-124)

Third Edition

4.5 The master method for solving recurrences

4.6.1 The proof for exact powers

The first part of the proof of the master theorem analyzes the recurrence (4.20) T .n/ D aT .n=b/ C f .n/ ;

for the master method, under the assumption that n is an exact power of b > 1, where b need not be an integer. We break the analysis into three lemmas. The first reduces the problem of solving the master recurrence to the problem of evaluating an expression that contains a summation. The second determines bounds on this summation. The third lemma puts the first two together to prove a version of the master theorem for the case in which n is an exact power of b.

Lemma 4.2

Let a  1 and b > 1 be constants, and let f .n/ be a nonnegative function defined on exact powers of b. Define T .n/ on exact powers of b by the recurrence

T .n/ D (

‚.1/ if n D 1 ;

aT .n=b/ C f .n/ if n D bi; where i is a positive integer. Then T .n/ D ‚.nlogba/ C

logXbn1 j D0

ajf .n=bj/ : (4.21)

Proof We use the recursion tree in Figure 4.7. The root of the tree has cost f .n/, and it has a children, each with cost f .n=b/. (It is convenient to think of a as being

Figure 4.7 The recursion tree generated by T .n/ D aT .n=b/ C f .n/. The tree is a complete a-ary tree with nlogbaleaves and height logbn. The cost of the nodes at each depth is shown at the right, and their sum is given in equation (4.21).

an integer, especially when visualizing the recursion tree, but the mathematics does not require it.) Each of these children has a children, making a2nodes at depth 2, and each of the a children has cost f .n=b2/. In general, there are aj nodes at depth j , and each has cost f .n=bj/. The cost of each leaf is T .1/ D ‚.1/, and each leaf is at depth logbn, since n=blogbn D 1. There are alogbn D nlogba leaves in the tree.

We can obtain equation (4.21) by summing the costs of the nodes at each depth in the tree, as shown in the figure. The cost for all internal nodes at depth j is ajf .n=bj/, and so the total cost of all internal nodes is

logXbn1 j D0

ajf .n=bj/ :

In the underlying divide-and-conquer algorithm, this sum represents the costs of dividing problems into subproblems and then recombining the subproblems. The

cost of all the leaves, which is the cost of doing all nlogba subproblems of size 1, is ‚.nlogba/.

In terms of the recursion tree, the three cases of the master theorem correspond to cases in which the total cost of the tree is (1) dominated by the costs in the leaves, (2) evenly distributed among the levels of the tree, or (3) dominated by the cost of the root.

The summation in equation (4.21) describes the cost of the dividing and com-bining steps in the underlying divide-and-conquer algorithm. The next lemma pro-vides asymptotic bounds on the summation’s growth.

Lemma 4.3

Let a  1 and b > 1 be constants, and let f .n/ be a nonnegative function defined on exact powers of b. A function g.n/ defined over exact powers of b by

g.n/ D

logXbn1 j D0

ajf .n=bj/ (4.22)

has the following asymptotic bounds for exact powers of b:

1. If f .n/ D O.nlogba/ for some constant  > 0, then g.n/ D O.nlogba/.

2. If f .n/ D ‚.nlogba/, then g.n/ D ‚.nlogbalg n/.

3. If af .n=b/  cf .n/ for some constant c < 1 and for all sufficiently large n, then g.n/ D ‚.f .n//.

Proof For case 1, we have f .n/ D O.nlogba/, which implies that f .n=bj/ D O..n=bj/logba/. Substituting into equation (4.22) yields

g.n/ D O

We bound the summation within the O-notation by factoring out terms and simpli-fying, which leaves an increasing geometric series:

logXbn1

D nlogba O.nlogba/. Substituting this expression for the summation in equation (4.23) yields g.n/ D O.nlogba/ ;

thereby proving case 1.

Because case 2 assumes that f .n/ D ‚.nlogba/, we have that f .n=bj/ D

‚..n=bj/logba/. Substituting into equation (4.22) yields g.n/ D ‚

We bound the summation within the ‚-notation as in case 1, but this time we do not obtain a geometric series. Instead, we discover that every term of the summation is the same:

Substituting this expression for the summation in equation (4.24) yields g.n/ D ‚.nlogbalogbn/

D ‚.nlogbalg n/ ; proving case 2.

We prove case 3 similarly. Since f .n/ appears in the definition (4.22) of g.n/

and all terms of g.n/ are nonnegative, we can conclude that g.n/ D .f .n// for exact powers of b. We assume in the statement of the lemma that af .n=b/  cf .n/

for some constant c < 1 and all sufficiently large n. We rewrite this assumption as f .n=b/  .c=a/f .n/ and iterate j times, yielding f .n=bj/  .c=a/jf .n/ or, equivalently, ajf .n=bj/  cjf .n/, where we assume that the values we iterate on are sufficiently large. Since the last, and smallest, such value is n=bj 1, it is enough to assume that n=bj 1is sufficiently large.

Substituting into equation (4.22) and simplifying yields a geometric series, but unlike the series in case 1, this one has decreasing terms. We use an O.1/ term to

capture the terms that are not covered by our assumption that n is sufficiently large:

g.n/ D

logXbn1 j D0

ajf .n=bj/



logXbn1 j D0

cjf .n/ C O.1/

 f .n/

X1 j D0

cj C O.1/

D f .n/

 1

1  c



C O.1/

D O.f .n// ;

since c is a constant. Thus, we can conclude that g.n/ D ‚.f .n// for exact powers of b. With case 3 proved, the proof of the lemma is complete.

We can now prove a version of the master theorem for the case in which n is an exact power of b.

Lemma 4.4

Let a  1 and b > 1 be constants, and let f .n/ be a nonnegative function defined on exact powers of b. Define T .n/ on exact powers of b by the recurrence

T .n/ D (

‚.1/ if n D 1 ;

aT .n=b/ C f .n/ if n D bi;

where i is a positive integer. Then T .n/ has the following asymptotic bounds for exact powers of b:

1. If f .n/ D O.nlogba/ for some constant  > 0, then T .n/ D ‚.nlogba/.

2. If f .n/ D ‚.nlogba/, then T .n/ D ‚.nlogbalg n/.

3. If f .n/ D .nlogbaC/ for some constant  > 0, and if af .n=b/  cf .n/ for some constant c < 1 and all sufficiently large n, then T .n/ D ‚.f .n//.

Proof We use the bounds in Lemma 4.3 to evaluate the summation (4.21) from Lemma 4.2. For case 1, we have

T .n/ D ‚.nlogba/ C O.nlogba/ D ‚.nlogba/ ;

and for case 2,

T .n/ D ‚.nlogba/ C ‚.nlogbalg n/

D ‚.nlogbalg n/ : For case 3,

T .n/ D ‚.nlogba/ C ‚.f .n//

D ‚.f .n// ; because f .n/ D .nlogbaC/.

在文檔中 ALGORITHMS INTRODUCTION TO (頁 119-124)