Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS...

20
Design and Analysis of Algorithms

Transcript of Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS...

Page 1: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Design and Analysis of Algorithms

Page 2: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

This Class

Page 3: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Website and ContactWebsite

I www.cs.kent.edu/~aleitert/daa/I Important informationI SlidesI AnnouncementsEmail

I [email protected]

3 / 19

Page 4: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Primary Textbook

A L G O R I T H M SI N T R O D U C T I O N T O

T H I R D E D I T I O N

T H O M A S H.

C H A R L E S E.

R O N A L D L .

C L I F F O R D S T E I N

R I V E S T

L E I S E R S O N

C O R M E NIntroduction to Algorithms,by Cormen et al.3rd edition, MIT Press, 2009Primary source for this class.

4 / 19

Page 5: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Other TextbooksThe Algorithm Design Manual,by Steven S. Skiena2nd edition, Springer, 2008PDF-Version available for free atSpringer Link

5 / 19

Page 6: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Other Textbooks

ptg

Algorithms, 4th Edition,by Robert Sedgewick and Kevin Wayne4th edition, Addison-Wesley Professional, 2011

Algorithm Design: Foundations, Analysis, and InternetExamples,by Michael T. Goodrich and Roberto Tamassia, 1stedition, Wiley, 2001

6 / 19

Page 7: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Clarification

ClarificationYou do not need (to buy) a textbook. These are recommendations if youare looking for a textbook to study.

7 / 19

Page 8: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Course RequirementsExam 1 33.3% June 30, during classExam 2 33.3% July 19, during classExam 3 33.3% Aug 4, during class(Dates may change.)Exams

I closed book examinationI one handwritten sheet (one side) allowedHomework

I Will not be graded.I Good preparation for exams.

8 / 19

Page 9: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Office HoursOn appointmentRoom 352, Math and CS BuildingSend me an email if you want to meet.

9 / 19

Page 10: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Academic Presence VerificationDue to federal rules, instructors “must verify that students beginattendance in each course for which they are registered.”Required to receive federal financial aid.Verification of Your Attendance

I Sign attendance sheet once.

10 / 19

Page 11: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Algorithms

Page 12: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

AlgorithmQuestionWhat is an algorithm?

WikipediaAn algorithm is a self-contained step-by-step set of operations to beperformed. [...] An algorithm is an effective method that can beexpressed within a finite amount of space and time [...] forcalculating a function. Starting from an initial state and initial input,the instructions describe a computation that [...] proceeds through afinite number of well-defined successive states, eventually producing“output” and terminating at a final ending state.

12 / 19

Page 13: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

AlgorithmQuestionWhat is an algorithm?

WikipediaAn algorithm is a self-contained step-by-step set of operations to beperformed. [...] An algorithm is an effective method that can beexpressed within a finite amount of space and time [...] forcalculating a function. Starting from an initial state and initial input,the instructions describe a computation that [...] proceeds through afinite number of well-defined successive states, eventually producing“output” and terminating at a final ending state.

12 / 19

Page 14: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Algorithm

AlgorithmInput Output

13 / 19

Page 15: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Properties of AlgorithmsCorrectness

I Will it produce the desired output?I We will prove that our algorithms are correct.Efficiency

I How fast is the algorithm?I How much resources does it need?I Is there a faster algorithm?Having one of both properties is (usually) easy. However, having both is thegoal.

14 / 19

Page 16: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Example

Page 17: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Problem

Finding doublesYou are given two integer arrays A and B. Is there an integer i which is inboth arrays?

16 / 19

Page 18: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Algorithm 1

1 For Each a ∈ A

2 For Each b ∈ B

3 If a = b Then4 Return “Yes”5 Return “No”

17 / 19

Page 19: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Algorithm 21 Sort A and B.2 Set i := 0 and j := 0.3 While i < |A| and j < |B |

4 If A[i ] = B[j ] Then5 Return “Yes”6 Else If A[i ] < B[j ] Then7 Set i := i + 1.8 Else If A[i ] > B[j ] Then9 Set j := j + 1.10 Return “No”

18 / 19

Page 20: Design and Analysis of Algorithms - Kentaleitert/daa/slides/00Introduction.pdfALGORITHMS INTRODUCTION TO THIRD EDITION THOMAS H. CHARLES E. RONALD L. CLIFFORDSTEIN RIVEST LEISERSON

Question

QuestionWhich algorithm is better and why?

19 / 19