cs 615: design & analysis of algorithms chapter 1: introduction, algorithmic notation and...

23
CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

Upload: aubrie-cain

Post on 03-Jan-2016

239 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

CS 615: Design & Analysis of

Algorithms

Chapter 1: Introduction, Algorithmic Notation and

Flowcharts

Page 2: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 2

Course Content

1.1. IntroductionIntroduction, , 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)

Page 3: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 3

Content

Text books, Lectures Assessments

Asymptotic NotationNotation for “the order of”Maximum RuleFlowchartsBasic Flowchart Constructions

Page 4: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 4

InstructorYusuf Altunel

Email:[email protected]

Web:http://web.iku.edu.tr/~yaltunel

Tel:(212) 498 42 10

Page 5: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 5

Text BooksMain Resources

Data Structures and Algorithm Analysis in C, 2nd Edition; Mark Allen Weiss; Addison Wesley Longman, 1997Fundamentals of Algorithmics; Gilles Brassard & Paul Bratley; Prentice-Hall, 1996.Data Structures, Algorithms & Software Principles, Thomas A. Standish, Addison Wesley, 1995.

Other ResourcesAlgorithms, Richard Johnsonbaugh and Marcus Schaefer, Pearson, 2004, ISBN 0-02-360692-4. http://condor.depaul.edu/~rjohnson/algorithm/index.htmlAlgorithm 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.

Page 6: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 6

LecturesCourses 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

Page 7: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 7

Follow up the courseUse the web page of the coursehttp://web.iku.edu.tr/~yaltunel/Spring2005/CS615

Use the email group of the courseSend an empty email to subscribe:

[email protected] To send a message:

[email protected] access on web:

http://groups.yahoo.com/group/CS_615

Page 8: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 8

AssessmentParticipation

%10

Project%30

MidTerm%30

Final%40

BonusGrading: %110%10 Bonus

•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.

Page 9: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 9

Project

A real world application with dynamically constructed graph should be implemented until the end of the semester!Details will be announced later!

Page 10: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 10

Algorithmic Notation and Algorithmic Notation and Flowcharts (Brassard & Flowcharts (Brassard & Bratley Chp: Chapter 3)Bratley Chp: Chapter 3)

Page 11: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 11

Asymptotatic NotationUsed to express

The time taken by an algorithmWithin a multiplicative constant

PermitsSimplification in measuring other tangible things

Deals withThe behavior of functions in the limits

For sufficiently large parameters

An asymptotically superior algorithm is very often preferable

Page 12: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 12

Notation for “the order of”f:NR0 be an arbitrary function

from the natural numbersto the nonnegative numbers

The mathematical symbol order of isdenoted by O(f(n))the set of all functions t: NR0 such that

t(n) cf(n) for all nn0

O(f(n))={t: NR0 |(cR+)(nN)[t(n) cf(n)]}Examples

f(n)=n3-3n2-n-8 O(n3)f(n)= n3 O(n3)

Maximum Rule:Let f,g: NR0 be two arbitrary functionsO(f(n),g(n))=O(max(f(n),g(n)))

Page 13: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 13

Example for Maximum RuleAn algorithm that proceeds in three steps:

InitializationTake time in O(n2)

ProcessingTake time in O(n3)

FinalizationTake time in O(nlogn)

The complete algorithm takes time inO(n2 + n3 + nlogn)= O(max(n2,n3,nlogn))=O(n3)

Page 14: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 14

Results of Maximum RuleIf 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 + 1O(f(n))=O(n94)

Page 15: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 15

Scale of Strength for O-Notation

the relationship between order of functions

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)

Higher in order

Mor

e ef

fici

ent

Page 16: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 16

ExamplesWhat 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)

Page 17: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 17

Flowcharts

Process

Process

Decision

Data

Terminator

Display

Page 18: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 18

Basic Flowchart Constructions

FirstTask

NextTask

Sequence

Cond

ElsePart

ThenPart

F T

Cond

F

T

If Then Else Repeat-Until

Page 19: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 19

Basic Flowchart Constructions

Cond1

F

T

CondF

T

Selection (Case) While-Do

Cond2

...

T

Condn

F

T

...

Page 20: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 20

Basic Flowchart Constructions

for (i=1; i<n; i++) {..}for (<initialization>; <condition>; <post statement>) <statement>

initialization

Cond

statement

post statement

T

F

For statement

Page 21: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 21

Data Flow: Example

End

Cond1

Task2

FT

Start

Task1

Cond2

Task3

Task4

Cond3

FT

TF

StartTask1

if Cond1

thenif Cond2

then Task2

else Task3

else repeatTask4

until Cond3

End

Page 22: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 22

Example find Maximum

max<numberF

T

Start

get a number

max= infinitive

max=number

More numbers?T

end

Show max

T

F

Startmax= minimumdo

get a number if (max<number)then max = number

while more numbersshow max

End

Page 23: CS 615: Design & Analysis of Algorithms Chapter 1: Introduction, Algorithmic Notation and Flowcharts

April 20, 2023 CS 615 Design & Analysis of Algorithms 23

End of Chapter 1Introduction, Algorithmic Notation and Flowcharts