版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026贵州峰鑫建设投资(集团)有限公司招聘14人考试备考题库及答案解析
- 2026江苏南京大学招聘XZ2026-005商学院保洁员考试参考题库及答案解析
- 2026中国农业科学院农产品加工研究所食物营养与功能性食品创新团队招聘合同制科研助理考试参考试题及答案解析
- 2026江苏南京大学SZYJ20260004能源与资源学院博士后招聘1人考试参考题库及答案解析
- 2026江苏南京市东南大学网络空间安全学院劳务派遣岗位招聘1人考试参考试题及答案解析
- 2026河北衡水桃城区公开招聘医疗卫生岗位劳务派遣制工作人员5名考试备考试题及答案解析
- 2026湖北省面向西北农林科技大学普通选调生招录考试备考题库及答案解析
- 2026辽宁科技学院面向部分高校招聘5人考试参考试题及答案解析
- 2026福建福州工业园区开发集团有限公司设计勘察分公司招聘1人考试参考题库及答案解析
- 2026广东中山市公安局黄圃分局招聘警务辅助人员8人考试参考题库及答案解析
- 2025-2026学年四年级英语上册期末试题卷(含听力音频)
- 2026届川庆钻探工程限公司高校毕业生春季招聘10人易考易错模拟试题(共500题)试卷后附参考答案
- 医疗器械法规考试题及答案解析
- 2025年河南体育学院马克思主义基本原理概论期末考试笔试题库
- 2026年广西出版传媒集团有限公司招聘(98人)考试参考题库及答案解析
- 2026年中国铁路上海局集团有限公司招聘普通高校毕业生1236人备考题库及答案详解1套
- 2026年上海市普陀区社区工作者公开招聘备考题库附答案
- 医源性早发性卵巢功能不全临床治疗与管理指南(2025版)
- 甘肃省平凉市(2025年)辅警协警笔试笔试真题(附答案)
- 中国双相障碍防治指南(2025版)
- 移动式工程机械监理实施细则
评论
0/150
提交评论