《算法导论》第四章-第5节_练习(参考答案)

来源:互联网 发布:淘宝在哪开店 编辑:程序博客网 时间:2024/04/30 14:42

算法导论(第三版)参考答案:练习4.5-1,练习4.5-2,练习4.5-3,练习4.5-4,练习4.5-5

Exercise 4.5-1

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

  1. T(n)=2T(n/4)+1
  2. T(n)=2T(n/4)+n
  3. T(n)=2T(n/4)+n
  4. T(n)=2T(n/4)+n2
  1. a=2,b=4,f(n)=1.log42>0,满足情况一;解为

    T(n)=Θ(nlog42)=Θ(n)

  2. a=2,b=4,f(n)=n.log42=12,满足情况二;解为 T(n)=Θ(nlog42lgn)=Θ(nlgn)

  3. a=2,b=4,f(n)=n.log42<1,2f(n4)cf(n)(c=12),满足情况三;解为

    T(n)=Θ(n)

  4. a=2,b=4,f(n)=1.log42<2,2f(n4)cf(n)(c=18),满足情况三;解为

    T(n)=Θ(n2)

Exercise 4.5-2

Professor Caesar wishes to develop a matrix-multiplication algorithm that is asymptotically faster than Strassen’s algorithm. His algorithm will use the divide-and-conquer method, dividing each matrix into pieces of size n/4×n/4, and the divide and combine steps together will take Θ(n2) time. He needs to determine how many subproblems his algorithm has to create in order to beat Strassen’s algorithm. If his algorithm creates asubproblems, then the recurrence for the running time T(n) becomes T(n)=aT(n/4)+Θ(n2). What is the largest integer value of a for which Professor Caesar’s algorithm would be asymptotically faster than Strassen’s algorithm?

Strassen递归式:T(n)=7T(n/2)+Θ(n2)=Θ(nlg7)

情况三可以排除(矩阵乘法 T(n)>Θ(n2) );2log4a<lgn,16n<49,所以 n 最大值为48。

Exercise 4.5-3

Use the master method to show that the solution to the binary-search recurrence T(n)=T(n/2)+Θ(1) is T(n)=Θ(lgn). (See exercise 2.3-5 for a description of binary search).

a=1,b=2,f(n)=c.log21=0,,满足情况二;解为

T(n)=Θ(lgn)

Exercise 4.5-4

Can the master method be applied to the recurrence T(n)=4T(n/2)+n2lgn? Why or why not? Give an asymptotic upper bound for this recurrence.

a=4,b=2,f(n)=n2lgn.log24=2,f(n)=Ω(n2),,所以不满足情况三。主方法不适用

递归式:T(n)<4T(n/2)+n2+ε,ε 。则满足情况三,c>12ε 。最终T(n)<Θ(n2+ε)=O(n2+ε)

Exercise 4.5-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 a1 and b>1 and a function f(n) that satisfies all the conditions in case 3 of the master theorem, except the regularity condition.

假设存在递归式:T(n)=T(n/2)+n(2cosn)。其他情况都满足,除了

cn(2cosn)ccn2(2cosn2)2cos(n/2)2(2cosn)2cos(n/2)2(32cos2n/2)=2t64t21t1

t=1 时,c>32 。所以不满足正则条件。

阅读全文
0 0
原创粉丝点击