Skip to content

Latest commit

 

History

History
80 lines (52 loc) · 2.83 KB

4.3.md

File metadata and controls

80 lines (52 loc) · 2.83 KB

Exercises 4.3-1


Use the master method to give tight asymptotic bounds for the following recurrences.

a. ![](http://latex.codecogs.com/gif.latex? T(n) = 4T(n/2)+n )

b. ![](http://latex.codecogs.com/gif.latex? T(n) = 4T(n/2)+n^2 )

c. ![](http://latex.codecogs.com/gif.latex? T(n) = 4T(n/2)+n^3 )

Answer

![](http://latex.codecogs.com/gif.latex? n^{\log_{b}{a}} = n^{\log_{2}{4}} = n^2)

a. ![](http://latex.codecogs.com/gif.latex? \Theta(n^2) )

b. ![](http://latex.codecogs.com/gif.latex? \Theta(n^2 \lg{n}) )

c. ![](http://latex.codecogs.com/gif.latex? \Theta(n^3) )

Exercises 4.3-2


The recurrence T(n) = 7T (n/2)+n2 describes the running time of an algorithm A. A competing algorithm A′ has a running time of T′(n) = aT′(n/4) + n2. What is the largest integer value for a such that A′ is asymptotically faster than A?

Answer

根据主定理,算法A的运行时间为![](http://latex.codecogs.com/gif.latex? T(n) = \Theta(\lg{7})\ \approx n^{2.8} )

A'的运行时间在a > 16时超过n^2,此时

![](http://latex.codecogs.com/gif.latex? T(n) = \Theta(n^{\log_{4}{a}}) < \lg{7} = \log_{4}{49})

所以最大值为48

Exercises 4.3-3


Use the master method to show that the solution to the binary-search recurrence T(n) = T (n/2)

  • Θ(1) is T(n) = Θ(lg n). (See Exercise 2.3-5 for a description of binary search.)

Answer

![](http://latex.codecogs.com/gif.latex? n^{\log_{b}{a}} = n^{\log_{2}{1} = 1} )

so the solution is Θ(lgn).

Exercises 4.3-4


Can the master method be applied to the recurrence ![](http://latex.codecogs.com/gif.latex? T(n) = 4T(n/2) + n^2 \lg{n} ) Why or why not? Give an asymptotic upper bound for this recurrence.

Answer

![](http://latex.codecogs.com/gif.latex? n^{\log_{b}{a}} = n^{\log_{2}{4}} = n^2 )

The problem is that it is not polynomially larger. The ratio  ![](http://latex.codecogs.com/gif.latex? f(n) / n^{\log_{b}{a}} = \lg{n}) is asymptotically less than ![](http://latex.codecogs.com/gif.latex? n^\epsilon ) for any positive constant ![](http://latex.codecogs.com/gif.latex? \epsilon )

Exercises 4.3-5


Consider the regularity condition af (n/b) ≤ cf(n) for some constant c < 1, which is part of case 3 of the master theorem. Give an example of constants a ≥ 1 and b > 1 and a function f (n) that satisfies all the conditions in case 3 of the master theorem except the regularity condition.

Answer

let

a = 1
b = 2
f(n) = 2 - cos(n)

我们需要证明

![](http://latex.codecogs.com/gif.latex? \frac{n}{2}( 2 - \cos(\frac{n}{2})}) < cn \\ ~ \Rightarrow c > \frac{2- \cos(n/2)}{2} \\ ~ \Rightarrow c > \frac{3}{2} )


Follow @louis1992 on github to help finish this task.