算法与设计算法分析基础-整体框架讲解材料
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2020/7/11 2
How to describe an algorithm?
Natural language
• Step1 Input m and n.
• Step2 Divide m by n and assign the value of the remainder to r.
• Step3 If r=0, return the value of n as the answer and stop; otherwise, proceed to Step 4.
Goals of this lecture
At the end of this lecture, you should be able to • Describe how to analyze an algorithm • Understand what is a best-case, worse-case and
The notion of algorithm
• Input output finiteness effectiveness definiteness
Algorithm design pattern
2007-2008-01《Design and Analysis of Algorithms》SCUEC
Definition:
Algorithm analysis means to evaluate the two computer resources, time and space, which needed by an algorithm. Less resources an algorithm needs, more efficiency it is.
Issues:
• time efficiency
– Determines the amount of time that algorithm needs to be executed.
• space efficiency
– Determines the amount of space that algorithm needs to be executed.
2007-2008-01《Design and Analysis of Algorithms》SCUEC
2020/7/11 6
Chapter 2
Fundamentals of the Analysis of Algorithm Efficiency (I)
1、The framework to analyze algorithms 2、Best, worst, average-case analysis 3、Three asymptotic notations
average-case analysis • Master the three asymptotic notations , , O,
rate of growth
2007-2008-01《Design and Analysis of Algorithms》SCUEC
2020/7/11 8
Analysis of algorithms
Approaches:
• theoretical analysis • empirical analysis
2007-2008-01《Design and Analysis of Algorithms》SCUEC
Review of last class
How to solve a problem by computer
• Actual problem • Mathematics model • Algorithm design and analysis • Programming • Result analysis
Start
Input m and n
r=mБайду номын сангаасn
r= 0
m=n n=r
Advantages: intuitive
output n
Disadvantages: lack flexibility
Stop
2007-2008-01《Design and Analysis of Algorithms》SCUEC
2020/7/11 3
How to describe an algorithm? (II)
Flow chart
A flowchart is a method of expressing an algorithm by a collection of connected geometric shapes containing descriptions of the algorithm’s steps.
2020/7/11 4
How to describe an algorithm? (IV)
Pseudocode
A pseudocode is a mixture of a natural language and programming language. It uses the basic grammar of programming language, but the operation instructions can designed with natural language.
• Step4 Assign the value of n to m and the value of r to n.
• Step5 Go to Step2.
Advantages: easy understand
Disadvantages: exist inherent ambiguity
2007-2008-01《Design and Analysis of Algorithms》SCUEC
1 r=m%n; 2 While r≠0
2.1 m=n; 2.2 n=r; 2.3 r=m%n; 3 return n;
Advantages: more precise than natural language
Disadvantages: not exist a single form of pseudocode