Algorithm & Analysis: Design
Algorithm & Analysis: Design
Course Info.
Prerequisites
CSc 4520: CSc 2720 and Math 3030 with grades of "C" or higher
CSc 6520: CSc 3410 and Math 3030
The department will strictly enforce all prerequisites. Students
without proper prerequisites will be dropped from the class,
without any prior notice, at any time during the semester.
30%
40%
For example:
The due date of Homework 1 is 09/01. Alice submits by 09/01
and gets 90 points; while she will get 70 if submitting after
09/01 but before 09/02, get 50 if submitting after 02/02 but
before 09/03; and only get 0 if submitting after 09/03
5
Course Outline
Basics of Algorithm Design and Analysis
Basic Concepts
Time Complexity (Running Time)
Data Structure
Import Data Structures: stack, queue, list, tree
Operations: search, insert, delete
Divide-and-Conquer
Key Idea
Recurrence Analysis
Selected Topics:
String Matching
Vertex-Cover Problem
Traveling-Salesman Problem
What is algorithm?
An algorithm is any well-defined computational
procedure that takes some value, or set of values,
as input and produces some value, or set of
values, as output.
Inputs
Algorithm
Procedure
Outputs
Why algorithm?
Stable Matching
Men: m and m
Women: w and w
Preference:
m prefers w to w
m prefers w to w
w prefers m to m
w prefers m to m
Correctness of Algorithm
An algorithm is said to be correct if, for every
input instance, it ends with the correct output.
Counter Example:
Computing the result of a divided by b.
Algorithm: return a/b as output
Input: a=6 and b=2 Output: 6/2=3
Input: a=5 and b=0 Output: error
11
Insertion Sorting
Key Idea: insert current number A[j] into sorted
sequence A[1, 2, , j-1].
Procedure:
for j = 2 to n do
key = A[j]
i=j-1
while i > 0 & A[i] > key do
A[i + 1] = A[i]
//move backward by one
position
i=i-1
A[i + 1] = key
key
key
key
key
13
Time Complexity
Depends on
input size
input quality (partially ordered)
Kinds of analysis
Worst case
(standard)
Average case
(sometimes)
14
Asymptotic Notations
BIG O: O
f = O(g) if f is no faster then g
f / g < some constant
O(g) indicates an upper bound
BIG OMEGA:
f = (g) if f is no slower then g
f / g > some constant
BIG Theta:
f = (g) if f has the same growth rate as g
some constant < f / g < some constant
15
Asymptotic Analysis
Ignore all the constants which are dependent on
machine and programming languages.
Analyze limiting behavior of complexity when the
input size increases, i.e., n
O(1) < O(log n) < O(n) < O(n log n) < O(n2)
< O(n3) < O(2n)
16
17
Exercises
Maximum Problem: find the maximum number of
a sequence number
How to do it?
What is time complexity?
18
Answers
Maximum Problem:
Key Idea: comparing any two neighboring numbers
19