计算机科学概论 课件Chap 05.pdf
Chapter 5: Algorithms
5-1
Chapter 5: Algorithms 算法
• 5.1 The Concept of an Algorithm
• 5.2 Algorithm Representation
• 5.3 Algorithm Discovery
• 5.4 Iterative Structures
• 5.5 Recursive Structures
• 5.6 Efficiency and Correctness
5-2
5.1 The Concept of an Algorithm
算法的概念
Definition of Algorithm 算法的定义
An algorithm is an ordered set of
unambiguous, executable steps
that defines a terminating process.
算法是定义一个可终止进程的一组有
序的、无歧义的、可执行的步骤的集
合
5-3
• Algorithm算法vs.Program程序vs.Process进程
– algorithm :an ordered set of unambiguous,
executable steps that defines a terminating
process.
–program :a formal representation of an
algorithm designed for computer application
–process :the activity of executing a program
鸡兔同笼问题。
大约在1500年前, 《孙子算经》中记载了这个有
趣的问题: “今有雉兔同笼,上有三十五头,
下有九十四足,问雉兔各几何?”
5-4
5.3 Algorithm Discovery算法的发现
• The development of a program consists of
two activities:
– discovering the underlying algorithm (most
challenging)
– representing that algorithm as a program.
• Polya’s Problem Solving Steps
– 1. Understand the problem.
– 2. Devise a plan for solving the problem.
– 3. Carry out the plan.
– 4. Evaluate the solution for accuracy and its
potential as a tool for solving other problems.
5-5
• The basic principles for problem-solving
1. Understand the problem.
2. Get an idea as to how an algorithmic procedure
might solve the problem.
3. Formulate the algorit