Anda di halaman 1dari 19

Algorithm Design & Analysis

Instructor: Dr. Wei (Lisa) Li


Department of Computer Science, GSU

Course Info.

CSc 4520/6520: Design and Analysis of Algorithm


Instructor: Dr. Wei (Lisa) Li
Office Hours: Wed. 2:00 - 4:00 PM
Office Room: Room 733, 25 Park Place
Email: wli28@gsu.edu
Phone: (404) 413-6658
TAs: Dongjing Miao & Iswarya Chidipudi
Email: dmiao1@student.gsu.edu & ichidipudi1@student.gsu.edu
Office Hours: Miao: Mon. 3:00 5:00 PM; Chidipudi (TBA)
Office Room: Miao: 725, 25 Park Place; Chidipudi (TBA)

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.

Materials & Assignments


Textbook:
Introduction to Algorithms (3rd Edition), Thomas H.
Cormen, Charles E. Leiserson, Ronald L. Rivest, and
Clifford Stein
Grading:
Weekly Homework (due on next Thursday) 30%
Midterm Exam (TBA)

30%

Final Exam (TBA)

40%

Homework Grading Policy

Full-Credit is 100 for on-time submission


Credit is reduced by 20 for 1-day overdue submission.
Credit is reduced by 40 for 2-day overdue submission.
Submission will not be accepted if it is overdue more than
2 days.

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

Course Outline (cont.)


Typical Algorithms:
Sorting Algorithms, Dynamic Programming, Greedy
Algorithms, and Graph Algorithms
Key Ideas
Time Complexity

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

How to make a stable matching for dating?


9

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

Corrected Algorithm: if b is non-zero, return a/b;


otherwise, return infinity.
10

Example: Insertion Sort


Problem: resorting a sequence number in a nondecreasing order
Input: a sequence with n numbers a1 , a2 ,..., an
Output: a a ... a
1
2
n

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

//A[i] <= key


12

Insertion Sorting (cont.)


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)

Best case (never)

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

Analysis of Insertion Sorting


Worst Case O(n2)

17

Exercises
Maximum Problem: find the maximum number of
a sequence number
How to do it?
What is time complexity?

Sort the following time complexity in a nonincreasing order


O(n4), O(logn), O(n), O(n!), O(n logn)

18

Answers
Maximum Problem:
Key Idea: comparing any two neighboring numbers

n-1 comparisons for n numbers


Sort the following time complexity in a nonincreasing order
O(n!), O(n4), O(n logn), O(n), O(logn)

19

Anda mungkin juga menyukai