算法导论答案.pdf_第1页
算法导论答案.pdf_第2页
算法导论答案.pdf_第3页
算法导论答案.pdf_第4页
算法导论答案.pdf_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Chapter 3 Michelle Bodnar, Andrew Lohr October 25, 2017 Exercise 3.1-1 Since we are requiring both f and g to be aymptotically non-negative, sup- pose that we are past some n1where both are non-negative (take the max of the two bounds on the n corresponding to both f and g). Let c1= .5 and c2= 1. 0 .5(f(n) + g(n) .5(max(f(n),g(n) + max(f(n),g(n) = max(f(n),g(n) max(f(n),g(n) + min(f(n),g(n) = (f(n) + g(n) Exercise 3.1-2 Let c = 2band n0 2a. Then for all n n0we have (n+a)b (2n)b= cnb so (n+a)b= O(nb). Now let n0 a 11/21/b and c = 1 2. Then n n0 a 11/21/b if and only if n n 21/b a if and only if n + a (1/2)a/bn if and only if (n+a)b cnb. Therefore (n+a)b= (nb). By Theorem 3.1, (n+a)b= (nb). Exercise 3.1-3 There are a ton of diff erent funtions that have growth rate less than or equal to n2. In particular, functions that are constant or shrink to zero arbitrarily fast. Saying that you grow more quickly than a function that shrinks to zero quickly means nothing. Exercise 3.1-4 2n+1 2 2nfor all n 0, so 2n+1= O(2n). However, 22nis not O(2n). If it were, there would exist n0and c such that n n0implies 2n2n= 22n c2n, so 2n c for n n0which is clearly impossible since c is a constant. Exercise 3.1-5 1 Suppose f(n) (g(n), then c1,c2,n0,n n0,0 c1g(n) f(n) c2g(n), if we just look at these inequalities saparately, we have c1g(n) f(n) (f(n) (g(n) and f(n) c2g(n) (f(n) O(g(n). Suppose that we had n1,c1,n n1,c1g(n) f(n) and n2,c2,n n2,f(n) c2g(n). Putting these together, and letting n0= max(n1,n2), we have n n0,c1g(n) f(n) c2g(n). Exercise 3.1-6 Suppose the running time is (g(n). By Theorem 3.1, the running time is O(g(n), which implies that for any input of size n n0the running time is bounded above by c1g(n) for some c1. This includes the running time on the worst-case input. Theorem 3.1 also imlpies the running time is (g(n), which implies that for any input of size n n0the running time is bounded below by c2g(n) for some c2. This includes the running time of the best-case input. On the other hand, the running time of any input is bounded above by the worst-case running time and bounded below by the best-case running time. If the worst-case and best-case running times are O(g(n) and (g(n) respec- tively, then the running time of any input of size n must be O(g(n) and (g(n). Theorem 3.1 implies that the running time is (g(n). Exercise 3.1-7 Suppose we had some f(n) o(g(n) (g(n). Then, we have 0 = lim n f(n) g(n) = a contradiction. Exercise 3.1-8 (g(n,m) = f(n,m) : there exist positive constants c,n0, and m0such that f(n,m) cg(n,m) for all n n0or m m0 (g(n,m) = f(n,m) : there exist positive constants c1,c2,n0, and m0such that c1g(n,m) f(n,m) c2g(n,m) for all n n0or m m0 Exercise 3.2-1 Let n1 0, so, the second term in this expression is greater than zero. The third term is nonnegative, so, the whole thing is 4e, then this is lim n 1 2n = 0 lim n nn n! = lim n 1 2n(1 + ( 1 n) en= lim n O(n.5)en lim n en c1n lim n en c1n = lim n en c1 = Exercise 3.2-4 The function dlogne! is not polynomially bounded. If it were, there would exist constants c, a, and n0such that for all n n0the inequality dlogne! cnawould hold. In particular, it would hold when n = 2kfor k N. Then 3 this becomes k! c(2a)k, a contradiction since the factorial function is not exponentially bounded. Well show that dloglogne! n. Without loss of generality assume n = 22 k. Then this becomes equivalent to showing k! 22 k, or 1 2(k 1) k 4 16 2822 k, which is clearly true for k 1. Therefore it is polynomially bounded. Exercise 3.2-5 Note that lg(2n) = 1 + lg(n), so, lim n lg(lg(n) lg(lg(n) = lim n lg(lg(2n) lg(lg(2n) = lim n lg(1 + lg(n) lg(n) = lim n lg(1 + n) n = lim n 1 1 + n = 0 So, we have that lg(lg(n) grows more quickly Exercise 3.2-6 2= 1 + 5 2 !2 = 6 + 25 4 = 1 + 1 + 5 2 = 1 + 2= 1 5 2 !2 = 6 25 4 = 1 + 1 5 2 = 1 + Exercise 3.2-7 First, we show that 1 + = 6+25 4 = 2. So, for every i, i1+ i2= i2( + 1) = i. Similarly for . For i = 0, 00 5 = 0. For i = 1, 1+5 2 1 5 2 5 = 5 5= 1. Then, by induction, Fi= Fi1+ Fi2= i1+i2(i1+i2) 5 = ii 5. Exercise 3.2-8 Let c1and c2be such that c1n klnk c2n. Then we have lnc1+ lnn = ln(c1n) ln(klnk) = lnk + ln(lnk) so lnn = O(lnk). Let c3be such that lnn c3lnk. Then n lnn n c3lnk k c2c3 4 so that n lnn = (k). Similarly, we have lnk + ln(lnk) = ln(klnk) ln(c2n) = ln(c2) + ln(n) so ln(n) = (lnk). Let c4be such that lnn c4lnk. Then n lnn n c4lnk k c1c4 so that n lnn = O(k). By Theorem 3.1 this implies n lnn = (k). By symmetry, k = ? n lnn ?. Problem 3-1 a. If we pick any c 0, then, the end behavior of cnk p(n) is going to infi nity, in particular, there is an n0so that for every n n0, it is positive, so, we can add p(n) to both sides to get p(n) 0, then, the end behavior of p(n)cnk is going to infi nity, in particular, there is an n0so that for every n n0, it is positive, so, we can add cnkto both sides to get p(n) cnk. c. We have by the previous parts that p(n) = O(nk) and p(n) = (nk). So, by Theorem 3.1, we have that p(n) = (nk). d. lim n p(n) nk = lim n nd(ad+ o(1) nk 1. Then this implies 1 kc c k2c2 = 1 k2c, a contradiction. f. True. Since f(n) = O(g(n) there exist c and n0such that n n0implies f(n) cg(n). Thus g(n) 1 cf(n), so g(n) = (f(n). g. False. Counterexample: Let f(n) = 22n. By exercise 3.1-4, 22n6= O(2n). h. True. Let g be any function such that g(n) = o(f(n). Since g is asymp- totically positive let n0be such that n n0implies g(n) 0.Then f(n) + g(n) f(n) so f(n) + o(f(n) = (f(n).Next, choose n1such that n n1implies g(n) f(n). Then f(n) + g(n) f(n) + f(n) = 2f(n) so f(n)+o(f(n) = O(f(n). By Theorem 3.1, this implies f(n)+o(f(n) = (f(n). 7 Problem 3-5 a. Suppose that we do not have that f = O(g(n).This means that c 0,n0,n n0,f(n) cg(n). Since this holds for every c, we can let it be arbitrary, say 1. Initially, we set n0= 1, then, the resulting n we will call a1. Then, in general, let n0= ai+ 1 and let ai+1be the resulting value of n. Then, on the infi nite set a1,a2,., we have f(n) g(n), and so, f = (g(n) This is not the case for the usual defi nition of . Suppose we had f(n) = n2(n mod 2) and g(n) = n. On all the even values, g(n) is larger, but on all the odd values, f(n) grows more quickly. b. The advantage is that you get the result of part a which is a nice property. A disadvantage is that the infi nite set of points on which you are making claims of the behavior could be very sparse. Also, there is nothing said about the behavior when outside of this infi nite set, it can do whatever it wants. c. A function f can only be in (g(n) if f(n) has an infi nite tail that is non negative. In this case, the defi nition of O(g(n) agrees with O0(g(n). Simi- larly, for a function to be in (g(n), we need that

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论