master method theorem

22
1 Asymptotic Efficiency of Recurrences Find the asymptotic bounds of recursive equations. Substitution method domain transformation • Changing variable Recursive tree method Master method (master theorem) • Provides bounds for: T(n) = aT(n/b)+f(n) where a 1 (the number of subproblems). b>1, (n/b is the size of each subproblem). f(n) is a given function.

Upload: rajendran

Post on 13-Apr-2017

36 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Master method theorem

1

Asymptotic Efficiency of Recurrences

• Find the asymptotic bounds of recursive equations.– Substitution method

• domain transformation• Changing variable

– Recursive tree method– Master method (master theorem)

• Provides bounds for: T(n) = aT(n/b)+f(n) where – a 1 (the number of subproblems).– b>1, (n/b is the size of each subproblem).– f(n) is a given function.

Page 2: Master method theorem

2

Recurrences

• MERGE-SORT– Contains details:• T(n) = (1) if n=1

T(n/2)+ T(n/2)+ (n) if n>1• Ignore details, T(n) = 2T(n/2)+ (n).

– T(n) = (1) if n=1

2T(n/2)+ (n) if n>1

Page 3: Master method theorem

3

Master Method/Theorem

• Theorem 4.1 (page 73)– for T(n) = aT(n/b)+f(n), n/b may be n/b or n/b. – where a 1, b>1 are positive integers, f(n) be a non-

negative function.1. If f(n)=O(nlogb

a-) for some >0, then T(n)= (nlogba).

2. If f(n)= (nlogba), then T(n)= (nlogb

a lg n).3. If f(n)=(nlogb

a+) for some >0, and if af(n/b) cf(n) for some c<1 and all sufficiently large n, then T(n)= (f(n)).

Page 4: Master method theorem

4

Implications of Master Theorem

• Comparison between f(n) and nlogba (<,=,>)

• Must be asymptotically smaller (or larger) by a polynomial, i.e., n for some >0.

• In case 3, the “regularity” must be satisfied, i.e., af(n/b) cf(n) for some c<1 .

• There are gaps – between 1 and 2: f(n) is smaller than nlogb

a, but not polynomially smaller.

– between 2 and 3: f(n) is larger than nlogba, but not

polynomially larger.– in case 3, if the “regularity” fails to hold.

Page 5: Master method theorem

5

Application of Master Theorem

• T(n) = 9T(n/3)+n; – a=9,b=3, f(n) =n– nlogb

a = nlog39 = (n2)

– f(n)=O(nlog39-) for =1

– By case 1, T(n) = (n2).

• T(n) = T(2n/3)+1– a=1,b=3/2, f(n) =1– nlogb

a = nlog3/21 = (n0) = (1)

– By case 2, T(n)= (lg n).

Page 6: Master method theorem

6

Application of Master Theorem

• T(n) = 3T(n/4)+nlg n; – a=3,b=4, f(n) =nlg n– nlogb

a = nlog43 = (n0.793)

– f(n)= (nlog43+) for 0.2

– Moreover, for large n, the “regularity” holds for c=3/4.• af(n/b) =3(n/4)lg (n/4) (3/4)nlg n = cf(n)

– By case 3, T(n) = (f(n))= (nlg n).

Page 7: Master method theorem

7

Exception to Master Theorem

• T(n) = 2T(n/2)+nlg n;– a=2,b=2, f(n) =nlg n– nlogb

a = nlog22 = (n)

– f(n) is asymptotically larger than nlogba , but not

polynomially larger because– f(n)/nlogb

a = lg n, which is asymptotically less than n for any >0.

– Therefore,this is a gap between 2 and 3.

Page 8: Master method theorem

8

Where Are the Gaps

nlogba f(n), case 2: within constant distancesc1

c2

n

f(n), case 1, at least polynomially smaller

Gap between case 1 and 2

n Gap between case 3 and 2f(n), case 3, at least polynomially larger

Note: 1. for case 3, the regularity also must hold. 2. if f(n) is lg n smaller, then fall in gap in 1 and 2 3. if f(n) is lg n larger, then fall in gap in 3 and 2 4. if f(n)=(nlogbalgkn), then T(n)=(nlogbalgk+1n). (as exercise)

Page 9: Master method theorem

9

Proof of Master Theorem• The proof for the exact powers, n=bk for k1.• Lemma 4.2– for T(n) = (1) if n=1– aT(n/b)+f(n) if n=bk for k1– where a 1, b>1, f(n) be a nonnegative function,– Then – T(n) = (nlogba)+ ajf(n/bj)

• Proof: – By iterating the recurrence– By recursion tree (See figure 4.3)

j=0

logbn-1

Page 10: Master method theorem

10

Recursion tree for T(n)=aT(n/b)+f(n)

Page 11: Master method theorem

11

Proof of Master Theorem (cont.)• Lemma 4.3:– Let a 1, b>1, f(n) be a nonnegative function defined on

exact power of b, then

– g(n)= ajf(n/bj) can be bounded for exact power of b as:

1. If f(n)=O(nlogba-) for some >0, then g(n)= O(nlogb

a).2. If f(n)= (nlogb

a), then g(n)= (nlogba lg n).

3. If f(n)= (nlogba+) for some >0 and if af(n/b) cf(n) for some

c<1 and all sufficiently large n b, then g(n)= (f(n)).

j=0

logbn-1

Page 12: Master method theorem

12

Proof of Lemma 4.3

• For case 1: f(n)=O(nlogba-) implies f(n/bj)=O((n /bj)logb

a-), so

• g(n)= ajf(n/bj) =O( aj(n /bj)logba- )

• = O(nlogba- aj/(blogb

a-)j ) = O(nlogba- aj/(aj(b-)j))

• = O(nlogba- (b)j ) = O(nlogb

a- (((b ) logbn-1)/(b-1) )

• = O(nlogba- (((blogbn) -1)/(b-1)))=O(nlogb

a n- (n -1)/(b-1))• = O(nlogb

a )

j=0

logbn-1

j=0

logbn-1

j=0

logbn-1

j=0

logbn-1

j=0

logbn-1

Page 13: Master method theorem

13

Proof of Lemma 4.3(cont.)

• For case 2: f(n)= (nlogba) implies f(n/bj)= ((n /bj)logb

a), so

• g(n)= ajf(n/bj) = ( aj(n /bj)logba)

• = (nlogba aj/(blogb

a)j ) = (nlogba 1)

• = (nlogba logb

n) = (nlogbalg n)

j=0

logbn-1

j=0

logbn-1

j=0

logbn-1

j=0

logbn-1

Page 14: Master method theorem

14

Proof of Lemma 4.3(cont.)

• For case 3:– Since g(n) contains f(n), g(n) = (f(n)) – Since af(n/b) cf(n), ajf(n/bj) cjf(n) , why???

– g(n)= ajf(n/bj) cjf(n) f(n) cj

– =f(n)(1/(1-c)) =O(f(n))– Thus, g(n)=(f(n))

j=0

logbn-1

j=0

logbn-1

j=0

Page 15: Master method theorem

15

Proof of Master Theorem (cont.)• Lemma 4.4:– for T(n) = (1) if n=1– aT(n/b)+f(n) if n=bk for k1– where a 1, b>1, f(n) be a nonnegative function,1. If f(n)=O(nlogb

a-) for some >0, then T(n)= (nlogba).

2. If f(n)= (nlogba), then T(n)= (nlogb

a lg n).3. If f(n)=(nlogb

a+) for some >0, and if af(n/b) cf(n) for some c<1 and all sufficiently large n, then T(n)= (f(n)).

Page 16: Master method theorem

16

Proof of Lemma 4.4 (cont.)• Combine Lemma 4.2 and 4.3, – For case 1: • T(n)= (nlogb

a)+O(nlogba)=(nlogb

a).

– For case 2: • T(n)= (nlogb

a)+(nlogba lg n)=(nlogb

a lg n).

– For case 3:• T(n)= (nlogb

a)+(f(n))=(f(n)) because f(n)= (nlogba+).

Page 17: Master method theorem

17

Floors and Ceilings • T(n)=aT(n/b)+f(n) and T(n)=aT(n/b)+f(n)• Want to prove both equal to T(n)=aT(n/b)+f(n)• Two results:– Master theorem applied to all integers n. – Floors and ceilings do not change the result.

• (Note: we proved this by domain transformation too).• Since n/bn/b, and n/b n/b, upper bound for

floors and lower bound for ceiling is held.• So prove upper bound for ceilings (similar for lower

bound for floors).

Page 18: Master method theorem

18

Upper bound of proof for T(n)=aT(n/b)+f(n)

• consider sequence n, n/b, n/b/b, n/b /b/b, …

• Let us define nj as follows:

• nj = n if j=0

• = nj-1/b if j>0• The sequence will be n0, n1, …, nlogbn

• Draw recursion tree:

Page 19: Master method theorem

19

Recursion tree of T(n)=aT(n/b)+f(n)

Page 20: Master method theorem

20

The proof of upper bound for ceiling

– T(n) = (nlogba)+ ajf(nj)

– Thus similar to Lemma 4.3 and 4.4, the upper bound is proven.

j=0

logbn -1

Page 21: Master method theorem

21

The simple format of master theorem

• T(n)=aT(n/b)+cnk, with a, b, c, k are positive constants, and a1 and b2,

O(nlogba), if a>bk.• T(n) = O(nklogn), if a=bk.

O(nk), if a<bk.

Page 22: Master method theorem

22

Summary Recurrences and their bounds– Substitution– Recursion tree– Master theorem. – Proof of subtleties – Recurrences that Master theorem does not

apply to.