×

Close

- Analysis and Design of Algorithms - DAA
- Note
**Amity University - AMITY**- Computer Science Engineering
- 20 Topics
**5639 Views**- 98 Offline Downloads
- Uploaded 2 years ago

Touch here to read

Page-3

- introduction - ( 1 - 8 )
- Problem types - ( 9 - 11 )
- Fundamentals of data structures - ( 12 - 17 )
- Fundamentals of the analysis of algorithm efficiency - ( 18 - 26 )
- Brute Force - ( 27 - 35 )
- Divide and Conquer - ( 36 - 37 )
- Merge sort - ( 38 - 47 )
- Decrease and conquer - ( 48 - 51 )
- DFS and BFS - ( 52 - 59 )
- Topological sorting - ( 60 - 63 )
- Transform and Conquer - ( 64 - 64 )
- Balanced search trees - ( 65 - 73 )
- Heaps - ( 74 - 80 )
- Dynamic programming - ( 81 - 85 )
- Warshall's Algorithm - ( 86 - 92 )
- Knapsack problem - ( 93 - 100 )
- Greedy Technique - ( 101 - 105 )
- Kruskal's algorithm - ( 106 - 128 )
- coping with the limitations of algorithm power - ( 129 - 142 )
- Travelling Salesperson problem - ( 143 - 148 )

Topic:

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

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)

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.

Another result is that it allows you to predict whether the software will meet any efficiency constraint that exits. Performance analysis There are any criteria upon which we can judge an algorithm for instance: 1. Does it do what we want to do? 2. Does it work correctly according to the original specifications to the task? 3. is there documentation that describes how to use it and how it works? 4. Are procedures created in such a way that they perform logical sub functions? 5. is the code readable? The space complexity of an algorithm is the amount of memory it needs to run to completion. The time complexity of an algorithm is the amount of computer time it needs to run to completion. Performance evaluation can be loosely divided into two major phases: (1) A priory estimate and (2) a posteriori testing. We refer to these performance analysis and performance measurements respectively. Space complexity (1)A fixed part that is independent of characteristics (e.g., number, size) of the inputs and outputs this part typically includes the instruction space (i.e. space for code), space for simple variables and fixed size component variables (also called aggregate),space for constants and so on. (2) A variable part that consist of space needed by component variable whose size is dependent on particular problem instance being solved, the space needed by referenced variables (to the extent that it depends on instance characteristics), and the recursion stack space (insofar and this space depends on the instance characteristics). The space requirement S(P) of an algorithm P may therefore be written as S(P) =c + SP (instance characteristics),where c is constant. When analyzing the space complexity of an algorithm, we concentrate solely on estimating SP (instance characteristics). For any given problem, we

## Leave your Comments