introduction of fundamental algorithm

15
1 Fundementals of Algorithms Fundementals of Algorithms Lec 1: Introduction Lec 1: Introduction CHP-1 Cormen et al CHP-1 Cormen et al General Web Resources General Web Resources

Upload: muhammad-huzaifa-chaudhary

Post on 18-Feb-2017

27 views

Category:

Education


0 download

TRANSCRIPT

Page 1: INTRODUCTION OF FUNDAMENTAL ALGORITHM

1

Fundementals of Algorithms Fundementals of Algorithms

Lec 1: IntroductionLec 1: IntroductionCHP-1 Cormen et alCHP-1 Cormen et alGeneral Web ResourcesGeneral Web Resources

Page 2: INTRODUCTION OF FUNDAMENTAL ALGORITHM

2

Recommended book and Other Recommended book and Other Material Material

Introduction to AlgorithmsIntroduction to Algorithms, by Cormen, , by Cormen, Leiserson and Rivest. Pub MIT Press 1990Leiserson and Rivest. Pub MIT Press 1990 Get the latest edition if possibleGet the latest edition if possible

Another book for referenceAnother book for reference Data Structures and Algorithms, by Aho, Data Structures and Algorithms, by Aho,

Hopcroft and Ullman, Pub Addision Wesley, Hopcroft and Ullman, Pub Addision Wesley, 19831983

Lecture SlidesLecture Slides Heavy input from web.Heavy input from web.

Page 3: INTRODUCTION OF FUNDAMENTAL ALGORITHM

3

AdministrativeAdministrative

Instructor: moizghauri Instructor: moizghauri [email protected]@yahoo.com

Page 4: INTRODUCTION OF FUNDAMENTAL ALGORITHM

4

AlgorithmsAlgorithms An algorithm is any well-defined An algorithm is any well-defined

computationalcomputational procedureprocedure that takes some that takes some value, or set of values, as value, or set of values, as inputinput and and produces some value, or set of values, as produces some value, or set of values, as outputoutput..

So it is a So it is a sequence of computational stepssequence of computational steps that transform the input into the output.that transform the input into the output.

A tool for solving a well-specified A tool for solving a well-specified computational problem.computational problem.

Page 5: INTRODUCTION OF FUNDAMENTAL ALGORITHM

5

Example: sortingExample: sorting

Input: Input: A sequence of n numbers A sequence of n numbers <a<a11,a,a22,a,a33…a…ann>>

Output: Output: A permutation (re-ordering) A permutation (re-ordering) <b<b11,b,b22,b,b33…b…bnn> of the input > of the input

sequencesequencesuch that such that b1<b2<b3…<bnb1<b2<b3…<bn

Page 6: INTRODUCTION OF FUNDAMENTAL ALGORITHM

6

Correctness of an algorithmCorrectness of an algorithm

An algorithm is said to be An algorithm is said to be correctcorrect if , for if , for every every input instanceinput instance,, it halts with the it halts with the correct output.correct output.

An incorrect algorithm An incorrect algorithm might not halt at all or some input instances, ormight not halt at all or some input instances, or It might halt with an answer other than desired It might halt with an answer other than desired

one.one.

Can incorrect algorithm be useful?Can incorrect algorithm be useful?

Page 7: INTRODUCTION OF FUNDAMENTAL ALGORITHM

7

Problems solved by algorithmsProblems solved by algorithms

Sorting/searching are by Sorting/searching are by no meanno mean the only the only computational problem for which computational problem for which algorithms have been developed.algorithms have been developed.

Otherwise we wouldn’t have the whole Otherwise we wouldn’t have the whole course on this topic?course on this topic?

Practical application of algorithms are Practical application of algorithms are ubiquitousubiquitous and include the following and include the following examplesexamples

Page 8: INTRODUCTION OF FUNDAMENTAL ALGORITHM

8

Practical applicationsPractical applications

The human Genome project: DNA The human Genome project: DNA sequence matchingsequence matching

Internet worldInternet world Shortest pathShortest path Matrices multiplication orderMatrices multiplication order

Page 9: INTRODUCTION OF FUNDAMENTAL ALGORITHM

9

Common about algorithmsCommon about algorithms There are many candidate solution, most of which There are many candidate solution, most of which

are not what we want, finding one that we do are not what we want, finding one that we do want can present quite a challenge.want can present quite a challenge.

Consider this exampleConsider this example

Mr. X has to Mr. X has to start start from city from city AA,,touch touch every otherevery othercity at least oncecity at least once and return and return Back to A. Find the Back to A. Find the route with lowest costroute with lowest cost. There is . There is at leastat leastone direct and several indirectone direct and several indirect routes between all routes between all

cities.cities.

A

B C

D3

11

10

8

4

Page 10: INTRODUCTION OF FUNDAMENTAL ALGORITHM

10

Common about algorithmsCommon about algorithmsABCDA = 22ABCDA = 22ABCADCA = 24 ABCADCA = 24 ABDCA = 16 ABDCA = 16

How many such combinations How many such combinations you will have to test? you will have to test?

A

B C

D3

11

10

8

4

Have to test Have to test all possible combinationsall possible combinations to to come up with the right solution. come up with the right solution. We will have to settle for an answer close We will have to settle for an answer close to the correct one. to the correct one.

Page 11: INTRODUCTION OF FUNDAMENTAL ALGORITHM

11

Data StructuresData Structures

A data structures is a way to store and A data structures is a way to store and organize data in order to facilitate access organize data in order to facilitate access and modifications.and modifications.

No single data structure works well for all No single data structure works well for all purposespurposes

Need to know the strengths and limitations Need to know the strengths and limitations of several of them.of several of them.

Page 12: INTRODUCTION OF FUNDAMENTAL ALGORITHM

12

TechniqueTechnique

Cant get a “cookbook” for algorithms?Cant get a “cookbook” for algorithms? Many problems you will encounter don’t Many problems you will encounter don’t

have any published algorithm.have any published algorithm. So need to learn “techniques” of So need to learn “techniques” of

algorithms design and analysisalgorithms design and analysis So you develop algorithms in your own, So you develop algorithms in your own,

show that they give correct answer and show that they give correct answer and understand their efficiency. understand their efficiency.

We will learn several such techniques in We will learn several such techniques in later part of this course.later part of this course.

Page 13: INTRODUCTION OF FUNDAMENTAL ALGORITHM

13

Algorithms and other Algorithms and other technologiestechnologies

Total system performance depends on Total system performance depends on choosing “efficient” algorithms as much as choosing “efficient” algorithms as much as choosing fast hardware.choosing fast hardware.

Page 14: INTRODUCTION OF FUNDAMENTAL ALGORITHM

14

Algorithms and other advanced Algorithms and other advanced technologiestechnologies

Hardware with high clock rates, Hardware with high clock rates, pipelining and superscalar architecture.pipelining and superscalar architecture.

Easy to use, intuitive graphical user Easy to use, intuitive graphical user interface (GUI’s)interface (GUI’s)

Local-area and wide-area networking.Local-area and wide-area networking.

Are algorithms as important as above Are algorithms as important as above technologies?technologies?

Page 15: INTRODUCTION OF FUNDAMENTAL ALGORITHM

15

Yes they are!Yes they are!

Algorithms are at the core of most Algorithms are at the core of most technologies used in computerstechnologies used in computers

Efficient algorithm can be used to solve Efficient algorithm can be used to solve larger problems than ever before.larger problems than ever before.