CS404 Design and Analysis of Algorithms

15
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)

description

CS404 Design and Analysis of Algorithms. BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani). Introduction. Algorithms : Definition: An algorithm is an unambiguous, ordered sequence of steps that are carried out to get a solution to a problem. - PowerPoint PPT Presentation

Transcript of CS404 Design and Analysis of Algorithms

Page 1: CS404 Design and Analysis of Algorithms

CS404 Design and Analysis of Algorithms

BBy DDr. M V S Peri SastryBB.E, PhD(BITS-Pilani)

Page 2: CS404 Design and Analysis of Algorithms

Introduction• Algorithms:• Definition: An algorithm is an unambiguous, ordered

sequence of steps that are carried out to get a solution to a problem.

• An algorithm is a technique to solve a problem systematically.

• It takes a set of input values and produces the desired output.

• A correct algorithm always outputs correct answer and halts.

• Several algorithms may exist to solve a given problem.

Page 3: CS404 Design and Analysis of Algorithms

Algorithms

Input Algorithm Output

Any algorithm should consist of the following:Input: The range of inputs for which an algorithm works perfectly. ( An algorithm without inputs may also exist sometimes)Output: An algorithm should always produce correct results and it should halt. (It should NOT hang)Algorithm:should have finite sequence of Instructions.

Page 4: CS404 Design and Analysis of Algorithms

Problem Soving on Computer

• Algorithms Should be written in simple English statements(pseudo code with mathematical expressions as needed.)

• In computer science, the relationship to external problems and Algorithms can be seen as below:

Computer Output

PROBLEM

INPUT

Algorithm

Page 5: CS404 Design and Analysis of Algorithms

Steps in Problem Solving

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 6: CS404 Design and Analysis of Algorithms

• Formulating the problem• with enough mathematical precision• we can ask a concrete question• start to solve it.

• Design the algorithm• list the “precise” steps. (an expert can translate

the algorithm into a computer program.)• Analyze the algorithm• prove that it is correct• establish the efficiency• the running time or sometimes space

The Process of Designing an Algorithm

Page 7: CS404 Design and Analysis of Algorithms

Properties Or Characteristics of Algorithms• Definiteness (Simple, Precise and Un-ambiguous)• Range of Inputs (should be specific)• Maintain Order (of execution of instructions)• Finite and correct (must solve problem in certain

steps )• Termination (must halt and terminate gracefully)• Speed (Time complexity) as desired for input• Space (RAM occupancy) as desired for input• Representable as Flowchart, Pseudo code, Code

Page 8: CS404 Design and Analysis of Algorithms

Effii c ient Euclid’s algorithm for GCD(Greatest Common Divisor)

• Algorithm GCD (m, n) in plain English• // Input: Two non-negative and non-zero integer

values m and n• Step1: if n = 0 return m and stop• Step2: Divide m by n and assign the reminder to r• Step3: Assign the value of n to m, and value of r to n• Step4: Go to Step1

Page 9: CS404 Design and Analysis of Algorithms

Efficient Euclid’s algorithm for GCD(Greatest Common Divisor) in pseudo code

• Algorithm GCD (m, n)• // Input: Two non-negative and non-zero integer

values m and n• Step1: [ display result] • if n = 0 return m and stop• Step2: [Compute GCD recursively]• Return GCD (n, m mod n);

Page 10: CS404 Design and Analysis of Algorithms

Efficient Euclid’s algorithm for GCD(Greatest Common Divisor) in some computer language

code• Algorithm GCD (m, n)• // Input: Two non-negative and non-zero integer

values m and n• While (n!= 0)

r = m mod nm = nn = r end whilereturn m// End of function

Page 11: CS404 Design and Analysis of Algorithms

• Correctness• Time Complexity as Input size increases

• Space Complexity ie; Memory requirement as Input size increases

• Establishing the efficiency• the running time and / or • sometimes space (RAM space)

The Process of Analysing an Algorithm

Page 12: CS404 Design and Analysis of Algorithms

Example of another Algorithm

Page 13: CS404 Design and Analysis of Algorithms

Application of Algorithms (Kinds Domains & Examples)

• Sorting, Searching, Shuffling Etc;• String processing• Graph problems• Combinatorial problems• Geometric problems• Numerical problems

Page 14: CS404 Design and Analysis of Algorithms

Application of Algorithms (Kinds Domains & Examples) continued

• Human Genome Project (100,000 Genes, 3 billion base pairs of human DNA ; data storage, search, analysis etc;)

• Internet (routing, search, analysis etc;)• E commerce • Public key cryptography and digital signatures

management• Manufacturing (Scheduling)• Flight scheduling etc;• Travelling Salesman’s problem etc;

Page 15: CS404 Design and Analysis of Algorithms

Thank YouQuestions and Discussion