Introduction To Algorithms
Introduction To Algorithms
of Computer Science
& Information Engineering
Introduction to Algorithms
Bioinformatics Laboratory,
Department of Computer Science & Information Engineering,
National Chung Cheng University. 1
Dept. of Computer Science
& Information Engineering
The Course
Introduction to the design and analysis of
algorithms.
This is not a programming course.
This course tells you what is a “good” program.
Reusability
Algorithm
2
Dept. of Computer Science
& Information Engineering
Text Book
Textbook: Introduction to Algorithms
(Second Edition).
Written by Cormen, Leiserson, Rivest, and Stein.
Published by MIT Press and McGraw-Hill.
3
Dept. of Computer Science
& Information Engineering
4
Dept. of Computer Science
& Information Engineering
Grading Policy
Midterm (Close Book) - 40%
Final (Close Book) - 40%
Homework - 20%
Quiz - extra 10%
5
Dept. of Computer Science
& Information Engineering
Teaching Information
Instructor
Yao-Ting Huang: [email protected]
Office: 511
Teaching Assistants
吳顯如: [email protected]
廖基復: [email protected]
Lab: 405
6
Dept. of Computer Science
& Information Engineering
What is Algorithm?
An algorithm is a sequence of computational
steps that transform input into the output.
In terms of software, an algorithm is considered to be
“good” if the CPU time and memory usage are
minimized.
7
Dept. of Computer Science
& Information Engineering
3,253,037,807 length.
Many hard problems lack of efficient algorithms.
9
Dept. of Computer Science
& Information Engineering
10
Dept. of Computer Science
& Information Engineering
Syllabus
Growth of Functions
Sorting Algorithms
Graph Algorithms
Dynamic Programming
Greedy Algorithms
Advanced Data Structures
Selected Topics
NP-completeness
11
Dept. of Computer Science
& Information Engineering
First Try
Fibonacci numbers F(n), for n = 0, 1, 2, …, are
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, …
Sunflowers have spirals in pair of adjacent Fibonacci numbers
for two directions and (e.g., 34 and 55) [Wikipedia]
12
Dept. of Computer Science
& Information Engineering
Algorithm 1: Recursion
Formal definition: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …
0 if n = 0
F (n) = 1 if n = 1
F (n − 1) + F (n − 2) if n > 1
Analysis of Algorithm 1
int fib (int n){
if(n == 0 || n == 1)
return 1;
Algorithm 1 else
return ( fib (n-1) + fib (n-2) );
}
fib(100) 1 = 20
fib(99 fib(98) 2 = 21
)
fib(98 fib(97 fib(97 fib(96 4 = 22
) ) ) )
100 fib(97 fib(96 … fib(96 fib(95 … 8 = 23
) ) ) )
…
fib(1 fib(0
) ) Exponential to n 16
Dept. of Computer Science
& Information Engineering
Analysis of Algorithm 2
result
tmp1 tmp2
Time Algorithm 2
18
n
Dept. of Computer Science
& Information Engineering
Algorithm 1
Time Algorithm 2
n
19
Dept. of Computer Science
& Information Engineering
Concluding Remarks
Ritchard Karp at NewYork Times (2006)
“Algorithms are good at describing dynamic
processes, while scientific formulas or equations are
more suited to static phenomena.”
“Algorithms are small but beautiful.”
20