清华大学第二版算法分析与设计课件第一章pdf

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Algorithm
An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.
• Theoretical analysis • Empirical analysis
Optimality
Design and Analysis of Algorithms - Chapter 1 7
Algorithm design strategies
Brute force Divide and conquer Decrease and conquer Transform and conquer
Instance: The sequence <5, 3, 2, 8, 3> Algorithms:
• • • • Selection sort Insertion sort Merge sort (many others)
Design and Analysis of Algorithmsign and Analysis of Algorithms - Chapter 1
2
Notion of algorithm
problem
algorithm
input
“computer”
output
Algorithmic solution
Design and Analysis of Algorithms - Chapter 1 3
9
What is an algorithm?
Recipe, process, method, technique, procedure, routine,… with following requirements: Finiteness
terminates after a finite number of steps 2. 3. 4. 5.
1.
Definiteness
rigorously and unambiguously specified
Input
valid inputs are clearly specified
Output
can be proved to produce the correct output given a valid input
Design and Analysis of Algorithms - Chapter 1 6
Basic Issues Related to Algorithms
How to design algorithms How to express algorithms Proving correctness Efficiency
How good is the algorithm?
• Correctness • Time efficiency • Space efficiency
Does there exist a better algorithm?
• Lower bounds • Optimality
Design and Analysis of Algorithms - Chapter 1
Practical importance
• A practitioner’s toolkit of known algorithms • Framework for designing and analyzing algorithms for new problems
Design and Analysis of Algorithms - Chapter 1
Design and Analysis of Algorithms - Chapter 1
1
Historical Perspective
Euclid’s algorithm for finding the greatest common divisor Muhammad ibn Musa al-Khwarizmi – 9th century mathematician /science/parshall/khwariz.html
Greedy approach Dynamic programming Backtracking and Branch and bound Space and time tradeoffs
Design and Analysis of Algorithms - Chapter 1
8
Analysis of Algorithms
Effectiveness
steps are sufficiently simple and basic
Design and Analysis of Algorithms - Chapter 1 10
Why study algorithms?
Theoretical importance
• the core of computer science
Design and Analysis of Algorithms - Chapter 1 5
Some Well-known Computational Problems
Sorting Searching Shortest paths in a graph Minimum spanning tree Primality testing Traveling salesman problem Knapsack problem Chess Towers of Hanoi Program termination
Selection Sort
Input: array a[1],…,a[n] Output: array a sorted in non-decreasing order Algorithm:
for i=1 to n swap a[i] with smallest of a[i],…a[n -1] • see also pseudocode, section 3.1
Example of computational problem: sorting
Statement of problem:
• Input: A sequence of n numbers <a1, a2, …, an> • Output: A reordering of the input sequence <a´1, a´2, …, a´n> so that a´i ≤ a´j whenever i < j
相关文档
最新文档