Design and Analysis of Algorithms: Mordecai Golin
Design and Analysis of Algorithms: Mordecai Golin
Revised 05/02/03
Comp 271
Mordecai Golin
Office: 3559
Email: golin@cs.ust.hk
http://www.cs.ust.hk/˜golin
1
Textbook and Lecture Notes
References: Recommendations
2
About COMP 271
3. Graph Algorithms.
3
We assume that you know
Big
notation and simple analysis of algorithms
Heaps
Hashing
4
Tentative Syllabus
Graphs:
– Review: Notation, Depth/Breadth First Search
– Cycle Finding & Topological Sort
– Minimum Spanning Trees: Kruskal’s and Prim’s algo-
rithms
– Dijkstra’s shortest path algorithm
5
Other Information
Average of
6
Classroom Etiquette
7
Lecture 1: Introduction
8
Example of Problems and Instances
Input: Sequence of numbers .
such that .
Instance of Problem:
9
Example of Algorithm: Insertion Sort
key;
10
Insertion Sort: an Incremental Approach
To sort a given array of length , at the th step it
sorts the array of the first items by making use of the
sorted array of the first items in the th
Step.
Example: Sort with Insertion Sort.
Step 1:
Step 2:
Step 3:
Step 4:
11
Analyzing Algorithms
12
Analyzing Algorithms – Continued
13
Three Cases of Analysis
14
Three Analyses of Insertion Sorting
Best Case: .
Worst Case: .
15
Big Oh
: is an asymptotically upper
bound for .
and
such that
for all
Remark: “ ” means that
Examples:
(1) .
(2) .
(3) .
(4) .
(5)
16
Big Omega
: is an asymptotically lower
bound for .
and
such that
for all
Examples:
(1) .
(2) .
(3) .
17
Big Theta
: is an asymptotically tight
bound for .
and
such that
for all
Examples:
(1)
(2)
18
Note that if
then
and
then
19
Some thoughts on Algorithm Design
“All other things being equal”, algo-
rithms will run more quickly than ones and
algorithms will beat ones.
20
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 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.
21