离散数学英文课件:DM_lecture3_3 Algorithmic Complexity_第1页
离散数学英文课件:DM_lecture3_3 Algorithmic Complexity_第2页
离散数学英文课件:DM_lecture3_3 Algorithmic Complexity_第3页
离散数学英文课件:DM_lecture3_3 Algorithmic Complexity_第4页
离散数学英文课件:DM_lecture3_3 Algorithmic Complexity_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

1、3.3: Algorithmic Complexity,The algorithmic complexity of a computation is a measure of how difficult it is to perform the computation. Some of the most common complexity measures: “Time” complexity: # of operations or steps required to solve a problem of size n. “Space” complexity: # of memory bits

2、 required to solve a problem of size n.,Complexity Depends on Input,Most algorithms have different complexities for inputs of different sizes. E.g. searching a long list typically takes more time than searching a short one. Therefore, complexity is usually expressed as a function of the input length

3、. This function usually gives the complexity for the worst-case or the average-case input of any given length.,Best、Worst and Average case,Efficiency may depend on the form of input: Best case: minimum over inputs of n Worst case: maximum over inputs of n When is the worst case time analysis importa

4、nt? Critical system (flight control) , Real-time system Average case: “average” over inputs of n NOT the average of worst and best case Expected cost under some assumption about the probability distribution of all possible inputs,Complexity & Orders of Growth,Suppose algorithm A has worst-case time

5、complexity f(n) for inputs of length n, while algorithm B (for the same task) takes time g(n). Suppose that fO(g). Which algorithm will be faster on all sufficiently-large, worst-case inputs? f(n) is at most order of g(n), and hence not slower,Example 1: Max algorithm,Problem: Find the simplest form

6、 of the exact order of growth () of the worst-case time complexity (w.c.t.c.) of the max algorithm, assuming that each line of code takes some constant time when it is executed (with possibly different times for different lines of code).,Complexity analysis, cont.,procedure max(a1, a2, , an: integer

7、s) v := a1t1 for i := 2 to nt2 if ai v then v := ait3 return vt4 w.c.t.c.:,Times for each execution of each line.,Complexity analysis, cont.,Now, what is the simplest form of the exact () order of growth of t(n)?,Example 2: Linear Search,procedure linear search (x: integer, a1, a2, , an: distinct in

8、tegers)i := 1t1while (i n x ai)t2 i := i + 1t3 if i n then location := it4 else location := 0 t5 return locationt6,Linear search analysis,Worst case time complexity order: Best case: Average case, if item is present:,Example 3: Binary Search,procedure binary search (x:integer, a1, a2, , an: distinct

9、 integers, sorted smallest to largest) i := 1 j := nwhile iam then i := m+1 else j := mendif x = ai then location := i else location := 0return location,(1),(1),(1),Key question:How many loop iterations?,Binary search analysis,Suppose that n is a power of 2, i.e., k: n=2k. Original range from i=1 to

10、 j=n contains n items. Each iteration: Size ji+1 of range is cut in half. Loop terminates when size of range is 1=20 (i=j). Therefore, the number of iterations is: k = log2n = (log2 n)= (log n) Even for n2k (not an integral power of 2),time complexity is still (log2 n) = (log n).,Names for some orders of growth,(1)Constant (logc n)Logarithmic (same order c) (logc n)Polylogarithmic (n)Linear (nc)Polynomial (for any c) (cn) Exponential (for c1) (n!)Factorial,(With c a constant.),NP Problems,Key Things to Know,Definitions of algorithmic complexity, time complex

温馨提示

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

最新文档

评论

0/150

提交评论