数据结构习题答案13章.ppt
《数据结构习题答案13章.ppt》由会员分享,可在线阅读,更多相关《数据结构习题答案13章.ppt(33页珍藏版)》请在三一办公上搜索。
1、数据结构与算法分析,任务:,1.讲解第一次作业:1.7 1.8 1.11 2.82.做题:2.9 2.10 2.123.第二次作业:3.1 3.3 3.5 3.10然后讲解 2 和34.做题:3.4 3.16 3.17 3.18讲解4,1.7,Every problem certainly does not have an algorithm.As discussed in Chapter 15(p482 15.3),there are a number of reasons why this might be the case.Some problems dont have a suffic
2、iently clear definition.Some problems,such as the halting problem,are non-computable.For some problems,such as one typically studied by artificial intelligence researchers,we simply dont know a solution.,TheHaltingProblem是问,输入一段程序代码和一个针对此程序的输入,能否编程判断运行这个程序后程序是否会终止。这个问题的答案是否定的。也就是说,不可能有一种算法可以正确判断一个指定
3、的程序运行后,给予指定的输入,程序最后出不出得来。,村子里有个理发师,这个理发师有条原则是,对于村里所有人,当且仅当这个人不自己理发,理发师就给这个人理发。如果这个人自己理发,理发师就不给这个人理发。无法回答的问题是,理发师给自己理发吗?,1.8,We must assume that by“algorithm”we mean something composed of steps are of a nature that they can be performed by a computer.If so,than any algorithmcan be expressed in C+.,In
4、 particular,if an algorithm can be expressed in any other computer programming language,then it can be expressed in C+,since all(sufficiently general)computer programming languages compute the same set of functions.,1.11,Students at this level are likely already familiar with binary search.Thus,they
5、 should typically respond with sequential search and binary search.Binary search should be described as better since it typically needs to make fewer comparisons(and thus is likely to be much faster).,二分查找的时间复杂度:O(logn)顺序查找时间复杂度:O(n)二分:总共有n个元素,渐渐跟下去就是n,n/2,n/4,.n/2k,其中k就是循环的次数 由于你n/2k取整后=1即令n/2k=1可得
6、k=log2n,(是以2为底,n的对数)所以时间复杂度可以表示O()=O(log2n),2.8,long ifact(int n)/make n=0),n*fact(n-1)(n-1)*fact(n-2)(n-2)*fact(n-3)(n-3)*fact(n-4)(n-4)*fact(n-5).3*fact(3-1)2*fact(2-1)11*2*3*4*n=n!,2.9,void rpermute(int*array,int n)swap(array,n-1,Random(n);rpermute(array,n-1);,2.10,Fibr is so much slower than Fib
7、i because Fibr re-computes the bulk of the series twice to get the two values to add.What is much worse,the recursive calls to compute the subexpressions also re-compute the bulk of the series,and do so recursively.The result is an exponentialexplosion.In contrast,Fibi computes each value in the ser
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 习题 答案 13
链接地址:https://www.31ppt.com/p-6578883.html