CS 615: Design & Analysis of Algorithms

Download Report

Transcript CS 615: Design & Analysis of Algorithms

CS 615:
Design & Analysis of Algorithms
Chapter 1: Introduction, Algorithmic
Notation and Flowcharts
Course Content
1. Introduction, Algorithmic Notation and Flowcharts
(Brassard & Bratley, Chap. 3)
2. Efficiency of Algorithms (Brassard & Bratley, Chap
2)
3. Basic Data Structures (Brassard & Bratley, Chap. 5)
4. Sorting (Weiss, Chap. 7)
5. Searching (Brassard & Bratley, Chap. 9)
6. Graph Algorithms (Weiss, Chap. 9)
7. Randomized Algorithms (Weiss, Chap. 10)
8. String Searching (Sedgewick, Chap. 19)
9. NP Completeness (Sedgewick, Chap. 40)
21 July 2015
CS 615 Design & Analysis of Algorithms
2
Content
Text books,
Lectures
Assessments
Asymptotic Notation
Notation for “the order of”
Maximum Rule
Flowcharts
Basic Flowchart Constructions
21 July 2015
CS 615 Design & Analysis of Algorithms
3
Instructor
Yusuf Altunel
Email:
[email protected]
Web:
http://web.iku.edu.tr/~yaltunel
Tel:
(212) 498 42 10
21 July 2015
CS 615 Design & Analysis of Algorithms
4
Text Books
Main Resources
Data Structures and Algorithm Analysis in C, 2nd Edition; Mark Allen
Weiss; Addison Wesley Longman, 1997
Fundamentals of Algorithmics; Gilles Brassard & Paul Bratley; PrenticeHall, 1996.
Data Structures, Algorithms & Software Principles, Thomas A. Standish,
Addison Wesley, 1995.
Other Resources
Algorithms, Richard Johnsonbaugh and Marcus Schaefer,
Pearson, 2004, ISBN 0-02-360692-4.
http://condor.depaul.edu/~rjohnson/algorithm/index.html
Algorithm Design: Foundations, Analysis, and Internet
Examples; Michael T. Goodrich & Roberto Tamassia; Wiley,
2002, ISBN 978-0-471-38365-9.
http://ww3.algorithmdesign.net/
Algorithms, Robert Sedgewick, Addison-Wesley 1983, e-book.
21 July 2015
CS 615 Design & Analysis of Algorithms
5
Lectures
Courses and labs
Day
Hours
Location
Theory
Thu
11:00-12:45 (2 Hours)
Lab 251
Lab
Fri
11:00-12:45 (2 Hours)
Lab 251
21 July 2015
CS 615 Design & Analysis of Algorithms
6
Follow up the course
Use the web page of the course
http://web.iku.edu.tr/~yaltunel/Spring2005/CS615
Use the email group of the course
Send an empty email to subscribe:
[email protected]
To send a message:
[email protected]
To access on web:
http://groups.yahoo.com/group/CS_615
21 July 2015
CS 615 Design & Analysis of Algorithms
7
Assessment
Participation
%10
Project
%30
MidTerm
%30
Final
•Please take care of the rules and regulations of the University.
•Otherwise you might be reported to the faculty, as well as
lose all bonus options of this course.
%40
Bonus
Grading: %110
%10 Bonus
21 July 2015
CS 615 Design & Analysis of Algorithms
8
Project
A real world application with dynamically
constructed graph should be implemented
until the end of the semester!
Details will be announced later!
21 July 2015
CS 615 Design & Analysis of Algorithms
9
Algorithmic Notation and
Flowcharts (Brassard & Bratley
Chp: Chapter 3)
21 July 2015
CS 615 Design & Analysis of Algorithms
10
Asymptotatic Notation
Used to express
The time taken by an algorithm
Within a multiplicative constant
Permits
Simplification in measuring other tangible things
Deals with
The behavior of functions in the limits
For sufficiently large parameters
An asymptotically superior algorithm is
very often preferable
21 July 2015
CS 615 Design & Analysis of Algorithms
11
Notation for “the order of”
f:NR0 be an arbitrary function
from the natural numbers
to the nonnegative numbers
The mathematical symbol order of is
denoted by O(f(n))
the set of all functions t: NR0 such that
t(n) cf(n) for all nn0
O(f(n))={t: NR0 |(cR+)(nN)[t(n) cf(n)]}
Examples
f(n)=n3-3n2-n-8  O(n3)
f(n)= n3 O(n3)
Maximum Rule:
Let f,g: NR0 be two arbitrary functions
O(f(n),g(n))=O(max(f(n),g(n)))
21 July 2015
CS 615 Design & Analysis of Algorithms
12
Example for Maximum Rule
An algorithm that proceeds in three steps:
Initialization
Take time in O(n2)
Processing
Take time in O(n3)
Finalization
Take time in O(nlogn)
The complete algorithm takes time in
O(n2 + n3 + nlogn)
= O(max(n2,n3,nlogn))
=O(n3)
21 July 2015
CS 615 Design & Analysis of Algorithms
13
Results of Maximum Rule
If t(n) is a complicated function
the most significant term of t(n) gives
the order of function discarding its coefficient
Example:
f(n)= 12n3- 5n2 + logn + 36
O(f(n))=O(n3)
f(n)= 999999n94 - 345n35 + 1
O(f(n))=O(n94)
21 July 2015
CS 615 Design & Analysis of Algorithms
14
Scale of Strength for O-Notation
21 July 2015
More efficient
O(1) < O(logn) < O(n) <
O(nlogn) < O(n2) < O(n3)
< O(2n) < O(10n)
O(1)
O(logn)
O(n)
O(nlogn)
O(n2)
O(n3)
O(2n)
O(10n)
CS 615 Design & Analysis of Algorithms
Higher in order
the relationship
between order of
functions
15
Examples
What is the order of 18nlog2n + 19n + 3
=O(18nlog2n + 19n + 3)
=O(max (nlogn, n, 3) )
=O(nlogn)
What is the order of n4 + 2n + 3nlogn + 3
=O(n4 + 2n + 3nlogn + 3)
=O(max (n4, 2n, nlogn , 3) )
=O(2n)
21 July 2015
CS 615 Design & Analysis of Algorithms
16
Flowcharts
Process
Data
Decision
Process
Display
Terminator
21 July 2015
CS 615 Design & Analysis of Algorithms
17
Basic Flowchart Constructions
First
Task
Next
Task
F
T
Cond
Else
Part
Then
Part
F
Cond
T
Sequence
21 July 2015
If Then Else
CS 615 Design & Analysis of Algorithms
Repeat-Until
18
Basic Flowchart Constructions
T
Cond1
F
T
Cond
F
Cond2
...
...
T
T
Condn
F
Selection (Case)
21 July 2015
While-Do
CS 615 Design & Analysis of Algorithms
19
Basic Flowchart Constructions
initialization
F
Cond
T
for (i=1; i<n; i++) {..}
for (<initialization>; <condition>; <post statement>) <statement>
statement
post statement
For statement
21 July 2015
CS 615 Design & Analysis of Algorithms
20
Data Flow: Example
Start
Task1
if Cond1
then
Start
Task1
T
T
Cond1
F
End
Task4
Cond2
Task2
F
if Cond2
then Task2
else Task3
else repeat
Task4
until Cond3
Task3
Cond3
F
T
End
21 July 2015
CS 615 Design & Analysis of Algorithms
21
Example find Maximum
Start
max= infinitive
Start
max= minimum
do
get a number
if (max<number)
then max = number
while more numbers
show max
get a number
T
F
max<number
max=number
T
More numbers?
F
T
End
Show max
end
21 July 2015
CS 615 Design & Analysis of Algorithms
22
End of Chapter 1
Introduction, Algorithmic
Notation and Flowcharts
21 July 2015
CS 615 Design & Analysis of Algorithms
23