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

来源:互联网 发布:中华遗产 知乎 编辑:程序博客网 时间:2024/05/21 06:56

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

Exercise 3.1-1

Let f(n)+g(n) be asymptotically nonnegative functions. Using the basic definition of Θ-notation, prove that max(f(n),g(n))=Θ(f(n)+g(n)).

假设max(f(n),g(n))f(n),则有

(f(n)+g(n))/2f(n)f(n)f(n)+g(n)

一定存在n0,对所有nn0,有012(f(n)+g(n))f(n)f(n)+g(n)。所以f(n)=Θ(f(n)+g(n))。同理可证max(f(n),g(n))g(n)的情况。

max(f(n),g(n))=Θ(f(n)+g(n))

Exercise 3.1-2

Show that for any real constants a and b, where b>0,

>(n+a)b=Θ(nb)>

多项式展开:

(n+a)b=(b0)nb+(b1)nb1a++(b0)ab=Θ(nb)

Exercise 3.1-3

Explain why the statement, “The running time of algorithm A is at least O(n2) is meaningless.

O表示一个渐进上界,“至少”是确定一个下界。

Exercise 3.1-4

Is 2n+1=O(2n)? Is 22n=O(2n)?

第一个正确。第二个错误22n=O(4n)

Exercise 3.1-5

Prove Theorem 3.1:

For any two functions f(n) and g(n), we have f(n)=Θ(g(n)) if and only if f(n)=O(g(n)) and f(n)=Ω(g(n)).

(根据渐进符号的数学表达式可知)

因为f(n)=Θ(g(n)),所以f(n)=O(g(n)),f(n)=Ω(g(n))

因为f(n)=O(g(n)),f(n)=Ω(g(n)),所以f(n)=Θ(g(n))

Exercise 3.1-6

Prove that the running time of an algorithm is Θ(g(n)) if and only if its worst-case running time is O(g(n)) and its best-case running time is Ω(g(n)).

同理exercise 3.1-5

Exercise 3.1-7

Prove o(g(n))ω(g(n)) is the empty set.

小o和小ω,都为非渐进精确界。即存在任意正常数c>0,有n1>0:0f(n)<cg(n);同时也存在同样的正常数c,有n2>0:0cg(n)<f(n)。对于n>max(n1,n2),可得f(n)<cg(n)<f(n),显然不存在。所以o(g(n))ω(g(n))为空。

Exercise 3.1-8

We can extend our notation to the case of two parameters n and m that can go to infinity independently at different rates.

For a given function g(n,m) we denote O(g(n,m)) the set of functions:

>>O(g(n,m)=>{f(n,m):>>there exist positive constants c,n0,and m0such that 0f(n,m)cg(n,m)for all nn0 or mm0.}>>

Give corresponding definitions for Ω(g(n,m)) and Θ(g(n,m)).

Ω(g(n,m)={f(n,m):there exist positive constants c,n0,and m0such that 0cg(n,m)f(n,m)for all nn0 or mm0.}

Ω(g(n,m)={f(n,m):there exist positive constants c1,c2,n0,and m0such that 0c1g(n,m)f(n,m)c2g(n,m)for all nn0 or mm0.}

阅读全文
0 0