《算法设计与分析基础》课程教学课件(PPT讲稿)Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency

Chapter 2 introduction to The Design & Fundamentals of the Analysis Analysis of Algorithms of Algorithm Efficiency 2ND EDITION Anany Levitin PEARSON Addison Wesley Copyright 2007 Pearson Addison-Wesley. All rights reserved
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved

Analysis of algorithms 口 Issues correctness time efficiency space efficiency optimality 口 Approaches theoretical analysis ° empirical analysIs Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-1 Analysis of algorithms Issues: • correctness • time efficiency • space efficiency • optimality Approaches: • theoretical analysis • empirical analysis

Theoretical analysis of time efficiency Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size o Basic operation: the operation that contributes the most towards the running time of the algorithm Input size ()c2C() running time execution time Number of times for basic operation basic operation is or cost executed Note: Different basic operations may cost differently Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-2 Theoretical analysis of time efficiency Time efficiency is analyzed by determining the number of repetitions of the basic operation as a function of input size Basic operation: the operation that contributes the most towards the running time of the algorithm T(n) ≈ copC(n) running time execution time for basic operation or cost Number of times basic operation is executed input size Note: Different basic operations may cost differently!

Input size and basic operation examples Problem Input size measure Basic operation Searching for key in a Number of list's items, Kev comparison list of n items l.e. n Multiplication of two Matrix dimensions or Multiplication of two matrices total number of elements numbers Checking primality of n'size= number of digits Di vIsIon a given integer n (in binary representation) Visiting a vertex or ypical graph problem #vertices and/oredges traversing an edge Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-3 Input size and basic operation examples Problem Input size measure Basic operation Searching for key in a list of n items Number of list’s items, i.e. n Key comparison Multiplication of two matrices Matrix dimensions or total number of elements Multiplication of two numbers Checking primality of a given integer n n’size = number of digits (in binary representation) Division Typical graph problem #vertices and/or edges Visiting a vertex or traversing an edge

Empirical analysis of time efficiency o Select a specific(typical) sample of inputs o Use physical unit of time(e.g, milliseconds) or Count actual number of basic operation's executions D Analyze the empirical data Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-4 Empirical analysis of time efficiency Select a specific (typical) sample of inputs Use physical unit of time (e.g., milliseconds) or Count actual number of basic operation’s executions Analyze the empirical data

Best-case, average-case, worst-case For some algorithms, efficiency depends on form of input: o Worst case: Worst(n)- maximum over inputs of size n o Best case: Cbest()- minimum over inputs of size n D Average case: Cavg(n)-"average over inputs of size n Number of times the basic operation will be executed on typical input NOT the average of worst and best case Expected number of basic operations considered as a random variable under some assumption about the probability distribution of all possible inputs. So, avg=expected under uniform distribution. Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2 2-5
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-5 Best-case, average-case, worst-case For some algorithms, efficiency depends on form of input: Worst case: Cworst(n) – maximum over inputs of size n Best case: Cbest(n) – minimum over inputs of size n Average case: Cavg(n) – “average” over inputs of size n • Number of times the basic operation will be executed on typical input • NOT the average of worst and best case • Expected number of basic operations considered as a random variable under some assumption about the probability distribution of all possible inputs. So, avg = expected under uniform distribution

Example: Sequential search ALGORITHM SequentialSearch(A[0.n-1, K) //Searches for a given value in a given array by sequential search //Input: An array A[O n-1 and a search key K //Output: The index of the first element of A that matches K or-1 if there are no matching elements ←0 while i< n and a[i]≠kdo ←-i+1 if i<n return i else return-1 口 Worst case n key comparisons 口 Best case comparisons D Average case (n+1)/2, assuming K is in A Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2 2-6
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-6 Example: Sequential search Worst case Best case Average case n key comparisons 1 comparisons (n+1)/2, assuming K is in A

Types of formulas for basic operation's count 口 Exact formula nn n Formula indicating order of growth with specific multiplicative constant eg,C(m)≈0.5m o Formula indicating order of growth with unknown multiplicative constant C(m)≈cn2 Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2 2-7
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-7 Types of formulas for basic operation’s count Exact formula e.g., C(n) = n(n-1)/2 Formula indicating order of growth with specific multiplicative constant e.g., C(n) ≈ 0.5 n 2 Formula indicating order of growth with unknown multiplicative constant e.g., C(n) ≈ cn2

Order of growth o Most important: Order of growth within a constant multiple as n->00 D Example: How much faster will algorithm run on computer that is twice as fast? How much longer does it take to solve problem of double input size? Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2 2-8
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-8 Order of growth Most important: Order of growth within a constant multiple as n→∞ Example: • How much faster will algorithm run on computer that is twice as fast? • How much longer does it take to solve problem of double input size?

Values of some important functions as n->00 og 272 3.31013.3101021 3.6.10 1026.61026.6-1021041061.310309.31015 10 01031.0.104106109 04131041.31056108102 171051.71061010 1015 106201062010710121018 Table 2.1 Values(some appraximate)of several functions important for analysis of algorithms Copyright 2007 Pearson Addison-Wesley. All rights reserved A Levitin "Intoducion to the Design Analysis of Algorithms, 2nd ed, Ch 2
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “Introduction to the Design & Analysis of Algorithms,” 2 nd ed., Ch. 2 2-9 Values of some important functions as n →
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 中国医科大学:《计算机基础》课程教学资源(PPT课件)第8章 Internet应用基础.ppt
- RDA Testing & Comparison with AACR2(session 1).ppt
- 《Computer Networking:A Top Down Approach》英文教材教学资源(PPT课件讲稿,6th edition)Chapter 2 Application Layer.ppt
- 《计算机网络》课程电子教案(PPT教学课件)第二章 物理层.pptx
- 同济大学:企业电子商务系统(PPT讲稿)Enterprise Electronic Business Systems.ppt
- 分布式数据库(PPT课件讲稿)Distributed DBMS Architecture.ppt
- 计算机网络 The Network Layer(PPT课件讲稿)网络互联、Internet上的网络层.ppt
- 《编码理论》课程电子教案(PPT课件讲稿)第二章 信息量和熵.ppt
- 《编译原理》课程教学资源(PPT课件讲稿)代码优化——全局数据流分析技术.ppt
- 网络应用软件(PPT课件讲稿)第一讲 客户-服务器概念、协议端口的使用、套接字API.ppt
- 西安电子科技大学:《微机原理与接口技术》课程教学资源(PPT课件讲稿)第一章 数制与码制(主讲:王晓甜).pptx
- 大连工业大学:《计算机文化与软件基础》课程教学资源(PPT课件讲稿)绪论、计算机系统的组成、计算机中数的表示.pps
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第4章 存储层次结构设计.pptx
- 中国科学技术大学:《数据结构及其算法》课程电子教案(PPT课件讲稿)第七章 图.pps
- 《计算机视觉》课程教学资源(PPT课件讲稿)基于灭点几何的深度图重建、基于焦点变换的深度图重建.ppt
- 《计算机网络》课程教学资源(PPT课件讲稿)第2章 物理层.ppt
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第三章 流水线技术.ppt
- 《Java Web编程技术》课程教学资源(PPT课件讲稿)第4章 JDBC数据库访问技术.ppt
- TTCN3工具培训(PPT讲稿)TTCN-3简介.ppt
- 《编译原理》课程教学资源(PPT课件讲稿)中间代码生成.pptx
- 中国科学技术大学:A Practical Verification Framework for Preemptive OS Kernels(PPT讲稿).ppt
- 《Computer Networking:A Top Down Approach》英文教材教学资源(PPT课件讲稿,6th edition)Chapter 2 Application Layer.ppt
- 《数据结构》课程教学资源(PPT课件讲稿)第五章 树.ppt
- 《Computer Networking:A Top Down Approach》英文教材教学资源(PPT课件讲稿,6th edition)Chapter 1 Introduction.ppt
- 《数据结构 Data Structure》课程教学资源(PPT课件讲稿)第四章 数组、串与广义表.ppt
- 中国科学技术大学:《现代密码学理论与实践》课程教学资源(PPT课件讲稿)第10章 密钥管理与其他公钥体制.pptx
- 中国科学技术大学:《算法基础》课程教学资源(PPT课件讲稿)第四讲 递归和分治策略(主讲人:吕敏).pptx
- 中国科学技术大学:《数值分析》课程教学资源(PPT课件讲稿)第1章 插值.ppt
- 《网络算法学》课程教学资源(PPT课件讲稿)第二部分 端节点算法学 第五章 拷贝数据.ppt
- 中国科学技术大学:《计算机体系结构》课程教学资源(PPT课件讲稿)第三章 流水线技术.pptx
- 北京航空航天大学:动态拼车服务中的高效插入操作(PPT讲稿)An Efficient Insertion Operator in Dynamic Ridesharing Services.pptx
- 西安电子科技大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)第一章 概述(主讲:马涛).pptx
- 计算机语言的学科形态与发展历程(PPT课件讲稿).ppt
- 西安电子科技大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)概述(主讲:岳鹏).ppt
- 南京航空航天大学:《C++》课程电子教案(PPT课件讲稿)第4章 类的高级部分.ppt
- 《神经网络和模糊系统》课程教学资源(PPT讲稿)第四章 突触动力学、非监督学习.ppt
- 《Computer Networking:A Top Down Approach》英文教材教学资源(PPT课件讲稿,4th edition)Chapter 1 Introduction.ppt
- 清华大学:不确定型决策(PPT讲稿)Decision Making under Uncertainty.pptx
- 西安电子科技大学:《计算机网络 Computer Networks》课程教学资源(PPT课件讲稿)第五章 传输层.pptx
- 《机器学习》课程教学资源(PPT课件讲稿)第七章 贝叶斯分类器 MACHINE LEARNING.pptx