×
Nothing in the world is more common than unsuccessful people with talent.

# Note for Analysis and Design of Algorithms - DAA By Amity Kumar

• Analysis and Design of Algorithms - DAA
• Note
• Amity University - AMITY
• Computer Science Engineering
• 20 Topics
• 5583 Views
Page-2

#### Note for Analysis and Design of Algorithms - DAA By Amity Kumar

Topic: / 148

0 User(s)

#### Text from page-2

COMPUTER Fig 1.a. An algorithm is composed of a finite set of steps, each of which may require one or more operations. The possibility of a computer carrying out these operations necessitates that certain constraints be placed on the type of operations an algorithm can include. The fourth criterion for algorithms we assume in this book is that they terminate after a finite number of operations. Criterion 5 requires that each operation be effective; each step must be such that it can, at least in principal, be done by a person using pencil and paper in a finite amount of time. Performing arithmetic on integers is an example of effective operation, but arithmetic with real numbers is not, since some values may be expressible only by infinitely long decimal expansion. Adding two such numbers would violet the effectiveness property. • Algorithms that are definite and effective are also called computational procedures. • The same algorithm can be represented in same algorithm can be represented in several ways • Several algorithms to solve the same problem • Different ideas different speed Example:

#### Text from page-3

Problem:GCD of Two numbers m,n Input specifiastion :Two inputs,nonnegative,not both zero Euclids algorithm -gcd(m,n)=gcd(n,m mod n) Untill m mod n =0,since gcd(m,0) =m Another way of representation of the same algorithm Euclids algorithm Step1:if n=0 return val of m & stop else proceed step 2 Step 2:Divide m by n & assign the value of remainder to r Step 3:Assign the value of n to m,r to n,Go to step1. Another algorithm to solve the same problem Euclids algorithm Step1:Assign the value of min(m,n) to t Step 2:Divide m by t.if remainder is 0,go to step3 else goto step4 Step 3: Divide n by t.if the remainder is 0,return the value of t as the answer and stop,otherwise proceed to step4 Step4 :Decrease the value of t by 1. go to step 2 1.3 Fundamentals of Algorithmic problem solving • Understanding the problem • Ascertain the capabilities of the computational device • Exact /approximate soln. • Decide on the appropriate data structure • Algorithm design techniques • Methods of specifying an algorithm • Proving an algorithms correctness • Analysing an algorithm

#### Text from page-4

Understanding the problem:The problem given should be understood completely.Check if it is similar to some standard problems & if a Known algorithm exists.otherwise a new algorithm has to be devised.Creating an algorithm is an art which may never be fully automated. An important step in the design is to specify an instance of the problem. Ascertain the capabilities of the computational device: Once a problem is understood we need to Know the capabilities of the computing device this can be done by Knowing the type of the architecture,speed & memory availability. Exact /approximate soln.: Once algorithm is devised, it is necessary to show that it computes answer for all the possible legal inputs. The solution is stated in two forms,Exact solution or approximate solution.examples of problems where an exact solution cannot be obtained are i)Finding a squareroot of number. ii)Solutions of non linear equations. Decide on the appropriate data structure:Some algorithms do not demand any ingenuity in representing their inputs.Someothers are in fact are predicted on ingenious data structures.A data type is a well-defined collection of data with a well-defined set of operations on it.A data structure is an actual implementation of a particular abstract data type. The Elementary Data Structures are ArraysThese let you access lots of data fast. (good) .You can have arrays of any other da ta type. (good) .However, you cannot make arrays bigger if your program decides it needs more space. (bad) . RecordsThese let you organize non-homogeneous data into logical packages to keep everything together. (good) .These packages do not include operations, just data fields (bad, which is why we need objects) .Records do not help you process distinct items in loops (bad, which is why arrays of records are used) SetsThese let you represent subsets of a set with such operations as intersection, union, and equivalence. (good) .Built-in sets are limited to a certain small size. (bad, but we can build our own set data type out of arrays to solve this problem if necessary)

#### Text from page-5

Algorithm design techniques: Creating an algorithm is an art which may never be fully automated. By mastering these design strategies, it will become easier for you to devise new and useful algorithms. Dynamic programming is one such technique. Some of the techniques are especially useful in fields other then computer science such as operation research and electrical engineering. Some important design techniques are linear, non linear and integer programming Methods of specifying an algorithm: There are mainly two options for specifying an algorithm: use of natural language or pseudocode & Flowcharts. A Pseudo code is a mixture of natural language & programming language like constructs. A flowchart is a method of expressing an algorithm by a collection of connected geometric shapes. Proving an algorithms correctness: Once algorithm is devised, it is necessary to show that it computes answer for all the possible legal inputs .We refer to this process as algorithm validation. The process of validation is to assure us that this algorithm will work correctly independent of issues concerning programming language it will be written in. A proof of correctness requires that the solution be stated in two forms. One form is usually as a program which is annotated by a set of assertions about the input and output variables of a program. These assertions are often expressed in the predicate calculus. The second form is called a specification, and this may also be expressed in the predicate calculus. A proof consists of showing that these two forms are equivalent in that for every given legal input, they describe same output. A complete proof of program correctness requires that each statement of programming language be precisely defined and all basic operations be proved correct. All these details may cause proof to be very much longer than the program. Analyzing algorithms: As an algorithm is executed, it uses the computers central processing unit to perform operation and its memory (both immediate and auxiliary) to hold the program and data. Analysis of algorithms and performance analysis refers to the task of determining how much computing time and storage an algorithm requires. This is a challenging area in which some times require grate mathematical skill. An important result of this study is that it allows you to make quantitative judgments about the value of one algorithm over another.