Académique Documents
Professionnel Documents
Culture Documents
Computer Algorithms
Spring 08
Chuan-Ming Liu
Computer Science & Information Engineering
NTUT, Taiwan
1
Mobile Computing & Software Engineering Lab
Instructor
Chuan-Ming Liu ()
Office: Room 502-3
Computer Science and Information Engineering
National Taipei University of Technology
TAIWAN
Phone: (02) 2771-2171 ext. 4251
Email: cmliu@csie.ntut.edu.tw
Office Hours: Thu 10:10-12:00 and Fri 10:10-12:00
2
Text Books
Introduction to Algorithms, 2nd edition. T. Cormen, C.
Leiserson, R. Rivest, and C. Stein. McGraw-Hill, 2001.
Supplementary Texts
1. Computer Algorithms /C++, 2nd Edition. E. Horowitz, S. Sahni, and S.
Rajasekaran, W.H. Freeman and Company, 1998.
2. Computer Algorithms, 3rd edition. S. Baase and A. V. Gelder. AddisonWesley, 2000.
3. Algorithms in C++, 3rd. R. Sedgewick. Addison-Wesley, 1998
4. Algorithms, R. Johnsonbaugh and M. Schaefer, Pearson Prentice Hall, 2004.
5. Algorithm Design, Jon Kleinberg and va Tardos, Pearson/Addison-Wesley,
2006.
6. Algorithms, Sanjoy Dasgupta, Christos Papadimitriou, Umesh Vazirani, McGrawHill, 2008.
Course Outline
Introduction
Asymptotic analysis
Recurrence Relations
Data Structures
Average and worst analysis
Lower Bounds
Dynamic Programming
Graph algorithms
Search and Traversal Techniques
NP-Completeness
Approximation Algorithms
New Trends in Algorithms
Course Work
First Thing to Do
Please visit the course web site
http://www.cc.ntut.edu.tw/~cmliu/Alg/NTUT_
Alg_S08g/index.htm
Send an email to me using the email
address:cmliu@csie.ntut.edu.tw. I will make a
mailing list for this course. All the
announcements will be broadcast via this
mailing list.
8
Introduction
Chuan-Ming Liu
Computer Science & Information Engineering
National Taipei University of Technology
TAIWAN
9
Outline
10
What is an Algorithm?
Definition
An algorithm is a finite set of instructions that, if
followed, accomplishes a particular task. All the
algorithms must satisfy the following criteria:
Input
Output
Definiteness
Effectiveness
Finiteness
11
What is an Algorithm ?
Definiteness: each instruction is clear and
unambiguous
Effectiveness: each instruction is
executable; in other words, feasibility
Finiteness: the algorithm terminates after
a finite number of steps.
12
What is an Algorithm ?
Input
Definiteness
Output
Effectiveness
Finiteness
Computational Procedures
13
14
Applications of Algorithms
Practical applications of algorithms are
ubiquitous, for example,
Human Genome Project
Internet
E-commerce (security issues)
Resource Management in Manufacturing
and other Commercial Setting
15
16
Al Kwarizmi
18
Leonardo Fibonacci
Corbis
19
Study on Algorithms
20
Describing Algorithms
Graphical view (flow charts)
Programming languages (C/C++, java, )
Pseudo-code representation
21
Pseudo-Code Conventions
Indentation as block structure
Loop and conditional constructs similar to
those in PASCAL, such as while, for, repeat,
if-then-else
Symbol as the comment in a line
Using instead of = and allowing i j e
Variables local to the given procedure
22
Pseudo-Code Conventions
Array element accessed by A[i] and A[1..j] as
the subarray of A
NIL representing the pointer referring to no
object
Call by value procedures
Please refer to page 19 on the textbook.
23
Sorting Problem
Input: Given a sequence of n elements,
a1, a2, , an
Output: a permutation of these n elements in
non-decreasing order
24
Example
10 40 25 36
10 25 36 40
10 25 36 40
25
26
27
Computing time
Time complexity: amount of time to complete an
algorithm
28
30
10
31
Designing Algorithms
Many techniques for designing algorithms and
we will discuss some of them in the class
Insertion sort uses an incremental approach
We now discuss divide-and-conquer
approach using merge sort as an example.
32
Divide-and-Conquer (1)
General Description
A problem having n inputs
Divide the problem into k sub-problems
Solve each sub-problem
Combine (merge) all the results of the subproblems to derive the solution of the problem
33
11
Divide-and-Conquer (2)
Can be implemented by a recursive algorithm
The computing time in general is
g ( n)
small n
T ( n) =
T
n
T
n
L
T
n
f
n
(
)
+
(
)
+
+
(
)
+
(
)
otherwise
2
k
1
Example
1
2
3
4
5
6
7
8
9 10
310 285 179 652 351 423 861 254 450 520
(1,5)
(1,3)
(1,2)
1
(4,5)
3
2
(6,10)
(6,8)
(6,7)
6
(9,10)
10
7
36
12
179 254 285 310 351 423 450 520 652 861
Merge Sort
38
Merge
39
13
40
Time Analysis
The merge process needs O(n) time since it
scans each element in worst case
a
n =1
T (n) =
2T (n / 2) + cn n > 1
T(n) = O(n log n)
41
14