ImageVerifierCode 换一换
格式:PPT , 页数:27 ,大小:125.50KB ,
资源ID:7281967      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7281967.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(算法设计与分析1Introduction.ppt)为本站会员(lxhqcj)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

算法设计与分析1Introduction.ppt

1、Introduction to Algorithm Analysis,Algorithm : Design & Analysis 1,Introduction to Algorithm Analysis,Goal of the Course Algorithm, the concept Algorithm Analysis: the critiria Average and Worst-Case Analysis Lower Bounds and the Complexity of Problems,Goal of the Course,Learning to solve real probl

2、ems that arise frequently in computer application Learning the basic principles and techniques used for answering the question: “How good, or, how bad is the algorithm” Getting to know a group of “very difficult problems” categorized as “NP-Complete”,Probably the Oldest Algorithm,Euclid algorithm in

3、put: nonnegative integer m,n output: gcd(m,n) procedure E1. n divides m, the remainderr E2. if r =0 then return n E3. nm; rn; goto E1,The Problem: Computing the greatest common divisor of two nonnegative integers,Specification,Euclid Algorithm: Recursive Version,Euclid algorithm input: nonnegative i

4、nteger m,n output: gcd(m,n) procedure Euclid(int m,n)if n=0then return melse return Euclid(n, m mod n),Specification,Recursion,Algorithm Pseudocode,Sequential Search, another Example,Procedure: Int seqSearch(int E, int n, int K)int ans, index;ans=-1;for (index=0; indexn; index+)if (K=Eindex)ans=inde

5、x;break; Return ans;,The Problem: Searching a list for a specific key. Input: an unordered array E with n entries, a key K to be matched Output: the location of K in E (or fail),Algorithmically Solvable Problem,Informally speaking A problem for which a computer program can be written that will produ

6、ce the correct answer for any input if we let it run long enough and allow it as much storage space as it needs. Unsolvable(or un-decidable) problem Problems for which no algorithms exist the Halting Problem for Turing Machine,Computational Complexity,Formal theory of the complexity of computable fu

7、nctions The complexity of specific problems and specific algorithms,Criteria for Algorithm Analysis,Correctness Amount of work done Amount of space used Simplicity, clarity Optimality,Correctness,Describing the “correctness”: the specification of a specified problem: Preconditions vs. post-condition

8、s Establishing the method: Preconditions+Algorithm post-conditions Proving the correctness of the implementation of the algorithm,Correctness of Euclid Algorithm,Euclid algorithm input: nonnegative integer m,n output: gcd(m,n) procedure Euclid(int m,n)if n=0then return melse return Euclid(n, m mod n

9、),How to Measure?,Not too general Giving some indication to make useful comparison for algorithms Not too precise Machine independent Language independent Programming style independent Implementation independent,Focusing the View,Counting the number of the passes through a loop while ignoring the si

10、ze of the loopThe operation of interest Search or sorting an array comparison Multiply 2 matrices multiplication Find the gcd bits of the inputs Traverse a tree processing an edge Non-iterative procedure procedure invocation,Presenting the Analysis Results,Amount of work done usually depends on the

11、size of the inputsAmount of work done usually doesnt depend on the size solely,Worst-case Complexity,Worst-case complexity, of a specified algorithm A for a specified problem P of size n: Giving the maximum number of operations performed by A on any input of size n Being a function of n Denoted as W

12、(n) W(n)=maxt(I) | IDn, Dn is the set of input,Worst-Case Complexity of Euclids,For any integer k1, if mn1 and nFk+1, then the call Euclid(m,n) makes fewer than k recursive calls. (to be proved) Since Fk is approximately , the number of recursive calls in Euclid is O(lgn).,Euclid(int m,n)if n=0then

13、return melse return Euclid(n, m mod n),measured by the number of recursive calls,Euclid Algorithm and Fibonacci,If mn1 and the invocation Euclid(m,n) performs k1 recursive calls, then mFk+2 and nFk+1. Proof by induction Basis: k=1, then n1=F2. Since mn, m2=F3. For larger k, Euclid(m,n) calls Euclid(

14、n, m mod n) which makes k-1 recursive calls. So, by inductive hypothesis, nFk+1, (m mod n)Fk. Note that m n+(m-m/nn) = n+(m mod n) Fk+1+Fk = Fk+2,Average Complexity,Weighted average A(n)How to get Pr(I) Experiences Simplifying assumption On a particular application,Pr(I) is the probability of ocurre

15、nce of input I,Average Behavior Analysis of Sequential Search,Case 1: assuming that K is in E Assuming no same entries in E Look all inputs with K in the ith location as one input (so, inputs totaling n) Each input occurs with equal probability (i.e. 1/n) Asucc(n)=i=0n-1Pr(Ii|succ)t(Ii)=i=0n-1(1/n)(

16、i+1)=(n+1)/2,Average Behavior Analysis of Sequential Search,Case 2: K may be not in E Assume that q is the probability for K in E A(n) = Pr(succ)Asucc(n)+Pr(fail) Afail(n)=q(n+1)/2)+(1-q)n Issue for discussion:Reasonable Assumptions,Optimality,“The best possible” How much work is necessary and suffi

17、cient to solve the problem. Definition of the optimal algorithm For problem P, the algorithm A does at most WA(n) steps in the worst case (upper bound) For some function F, it is provable that for any algorithm in the class under consideration, there is some input of size n for which the algorithm m

18、ust perform at least F(n) steps (lower bound) If WA=F, then A is optimal.,Complexity of the Problem,F is a lower bound for a class of algorithm means that: For any algorithm in the class, and any input of size n, there is some input of size n for which the algorithm must perform at least F(n) basic

19、operations.,Eastblishing a lower bound,Procedure: int findMax(E,n) max=E(0) for (index=1;indexn;index+)if (maxE(index)max=E(index); return max Lower bound For any algorithm A that can compare and copy numbers exclusively, if A does fewer than n-1 comparisons in any case, we can always provide a righ

20、t input so that A will output a wrong result.,The problem: Input: number array E with n entries indexed as 0,n-1 Output: Return max, the largest entry in E,Home Assignment,pp.61 1.5 1.12 1.16 1.19 Additional Other than speed, what other measures of efficiency might one use in a real-world setting? C

21、ome up with a real-world problem in which only the best solution will do. Then come up with one in which a solution that is “approximately” the best is good enough.,Algorithm vs. Computer Science,Sometimes people ask: “What really is computer science? Why dont we have telephone science? Telephone, i

22、t might be argued, are as important to modern life as computer are, perhaps even more so. A slightly more focused question is whether computer science is not covered by such classical disciplines as mathematics, physics, electrical engineering, linguistics, logic and philosophy.We would do best not

23、to pretend that we can answer these questions here and now. The hope, however, is that the course will implicitly convey something of the uniqueness and universality of the study of algorithm, and hence something of the importance of computer science as an autonomous field of study. - adapted from H

24、arel: “Algorithmics, the Spirit of Computing”,References,Classics Donald E.Knuth. The Art of Computer Programming Vol.1 Fundamental Algorithms Vol.2 Semi-numerical Algorithms Vol.3 Sorting and Searching Popular textbooks Thomas H.Cormen, etc. Introduction to Algorithms Robert Sedgewick. Algorithms (

25、with different versions using different programming languages) Advanced mathematical techniques Graham, Knuth, etc. Concrete Mathematics: A Foundation for Computer Science,You Have Choices,Design Techniques Oriented Textbooks Anany Levitin. Introduction to the Design and Analysis of Algorithms M.H.Alsuwaiyel. Algorithms Design Techniques and Analysis Evergreen Textbook Aho, Hopcroft and Ullman. The Design and Analysis of Computer Algorithm,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报