L01 PDF
L01 PDF
L01 PDF
Comp 271
Prof. Dekai WU
Office: Rm 3539
Email: dekai@cs.ust.hk
http://www.cs.ust.hk/dekai/271
1
Textbook and Lecture Notes
References: Recommendations
2
About COMP 271
3. Graph Algorithms.
5. String matching.
Heaps.
Hashing.
4
Tentative Syllabus
Graphs:
Depth-First Search - Applications of DFS (Articulation
Points, and Biconnected Components)
Minimum Spanning Trees: Kruskals and Prims algo-
rithms
Dijkstras shortest path algorithm
5
Other Information
6
Classroom Etiquette
7
Lecture 1: Introduction
8
Example of Problems and Instances
9
Example of Algorithm: Insertion Sort
for j=2 to n {
key = A[j];
i = j-1;
while (i >= 1 and A[i] > key) {
A[i+1] = A[i];
i--;
}
A[i+1] = key;
}
10
Insertion Sort: an Incremental Approach
Step 1: h6, 3, 2, 4i
Step 2: h3, 6, 2, 4i
Step 3: h2, 3, 6, 4i
Step 4: h2, 3, 4, 6i
11
Analyzing Algorithms
12
Analyzing Algorithms Continued
13
Three Cases of Analysis
14
Three Analyses of Insertion Sorting
| + 1 + 1{z+ + 1} = n 1 = (n).
1
n1
15
Analytical Time Complexity Analysis
16
Big-Oh
f (n) = O(g(n)):
17
When estimating the growth rate of T (n) using big-
Oh:
18
For example,
n2/2 3n = O(n2)
1 + 4n = O(n)
log2 n
log10 n = log = O(log2 n) = O(log n)
2 10
Pn
i 2 n n2 = O(n3)
i=1
i=1 i n n = O(n2)
Pn
19
Big Omega and Big Theta
20
Some thoughts on Algorithm Design
21
Note: After algorithm design one can continue on to
Algorithm tuning which would further concentrate on
improving algorithms by cutting cut down on the con-
stants in the big O() bounds. This needs a good un-
derstanding of both algorithm design principles and
efficient use of data structures. In this course we will
not go further into algorithm tuning. For a good intro-
duction, see chapter 9 in Programming Pearls, 2nd ed
by Jon Bentley.
22