the design and analysis of algorithms

14
The Design and Analysis of Algorithms by Anany Levitin Lecture notes prepared by Lydia Sinapova, Simpson College

Upload: zoltan

Post on 06-Jan-2016

35 views

Category:

Documents


0 download

DESCRIPTION

The Design and Analysis of Algorithms. by Anany Levitin Lecture notes prepared by Lydia Sinapova, Simpson College. CHAPTER 1: INTRODUCTION. What is an Algorithm Steps in Designing and Implementing an Algorithm Important Problem Types Fundamental Data Structures. ALGORITHM. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Design and Analysis of Algorithms

The Design and Analysis of Algorithms

by Anany Levitin

Lecture notes prepared by Lydia Sinapova, Simpson College

Page 2: The Design and Analysis of Algorithms

2

CHAPTER 1: INTRODUCTIONCHAPTER 1: INTRODUCTION

What is an Algorithm

Steps in Designing and Implementing an Algorithm

Important Problem Types

Fundamental Data Structures

Page 3: The Design and Analysis of Algorithms

3

ALGORITHM

A sequence of unambiguous

instructions for solving a

problem, i.e. for obtaining the

required output for any

legitimate input in

a finite amount of time

Page 4: The Design and Analysis of Algorithms

4

Important points

Non-ambiguityNon-ambiguity

Range of inputsRange of inputs

The same algorithm can be The same algorithm can be represented in different waysrepresented in different ways

Several algorithms for solving Several algorithms for solving the same problemthe same problem

Page 5: The Design and Analysis of Algorithms

5

gcd(m,n)

while n ≠0 dor ← m mod

n m ← n

n ← rreturn m

1. t ← min (m ,n)

2. if m % t = 0 goto 3,

else goto 4

3. if n % t = 0 return t,

else goto 4

4. t ← t - 15. goto 2

Page 6: The Design and Analysis of Algorithms

6

Understand the problem

Decide on computational meansExact vs approximate solution

Data structuresAlgorithm design technique

Design an algorithm

Prove correctness

Analyze the algorithm

Code the algorithm

Page 7: The Design and Analysis of Algorithms

7

What does it mean to understand the problem? What are the problem objects? What are the operations applied to the objects?

Deciding on computational means How the objects would be represented? How the operations would be implemented?

Page 8: The Design and Analysis of Algorithms

8

Design an algorithm

• Build a computational model of the solving process

Prove correctness

• Correct output for every legitimate input in finite time

• Based on correct math formula

• By induction

Page 9: The Design and Analysis of Algorithms

9

Analyze the algorithm

Efficiency: time and space

Simplicity

Generality: range of inputs, special cases

Optimality:no other algorithm can do

betterCodingHow the objects and operations in the algorithm are represented in the chosen programming language?

Page 10: The Design and Analysis of Algorithms

10

Important problem types

Sorting Searching String processing Graph problems Combinatorial problems Geometric problems Numerical problems

Page 11: The Design and Analysis of Algorithms

11

Fundamental data structures

Linear data structures Array Linked list Stack Queue

Operations: search, delete, insert

Implementation: static, dynamic

Page 12: The Design and Analysis of Algorithms

12

Non-linear data structures Graphs Trees : connected graph without

cyclesRooted trees

Ordered treesBinary trees

Graph representation: adjacency lists, adjacency matrix Tree representation: as graphs; binary nodes

Fundamental data structures

Page 13: The Design and Analysis of Algorithms

13

Fundamental data structures

Sets, Bags, Dictionaries Set: unordered collection of distinct

elements

Operations: membership, union, intersection

Representation: bit string; linear structure

Bag: unordered collection, elements may be repeated

Dictionary: a bag with operations search, add, delete

Page 14: The Design and Analysis of Algorithms

14

Conclusion

Algorithm classificationBy types of problemsBy design technique

Design techniquesa general approach to solving problems