MC0080-Analysis and Design of Algorithm
MC0080-Analysis and Design of Algorithm
Q1 Describe the following: (A) Well known Sorting Algorithms (B) Divide and Conquer Techniques
Ans 1(A) They are following:- insertion sort, bubble sort, selection sort, shell sort, heap sort well known Sorting Algorithms:Insertion sort:- It helps in sorting a list L of n numbers represented by an array A[1.....n] proceeds by picking up the numbers in the array from left one by one and each newly picked up number is placed at its relative position, w.r.t. the sorting order, among the earlier ordered ones
1. Bubble sort:- It helps in sorting a list L of n numbers represented by an array A[1.....n], proceeds by scanning the array from left to right. At each stage, compares adjacent pairs of numbers at positions A[i] and A[i+1] and whenever a pair of adjacent numbers is found to be out of order, then the positions at the numbers are exchanged. 2. Selection sort:- It is used for sorting a list L of n numbers, represented by an array A[1..n], proceeds by finding the maximum element of the array and placing it in the last position of the array representing the list. 3. Shell sort:- It is named so in honour of D.L short, who suggested the algorithm. It is also called diminishing- increment sort. 4. Heap sort:- Heap construction for a given array. Copy the root value to right-most yet-to-be occupied location of the array used to store the sorted values and copy the value in the last node of the tree to the root.
Ans 1(B) Divide and Conquer Techniques
1. Merge sort:- We recursively chop the list into two sub lists of almost equal sizes and when we get lists of get lists one, then start sorted merging of lists in the reverse order in which these lists were obtained through chopping. 2. Quick sort:- It is also called divide and conquer method of sorting. This method does more work in the first step of portioning the list into two sub lists. Then combining the two lists becomes trivial.
Q2. Explain in your own words the different asymptotic functions and notations.
Ans 2. The purpose of these asymptotic growth rate functions to be introduced is to facilitate the recognition of essential character of a complexity function through some simpler functions delivered by these notations. For example:- a complexity function ( ) + + , has essentially same ( ) behaviour as that of as the problem size n becomes larger and larger.
The Notation It provides asymptotic upper bound for a given functions each from the set of natural numbers or set of natural numbers or set of positive real numbers to positive real numbers
Q4. Discuss the process of flow of Strassens Algorithm and also its limitations.
Ans 4 The recursive algorithm for multiplying nn matrices is given below: 1. Partition the two matrices A, B into matrices 2. Conquer: Perform 7 multiplications recursively. 3. Combine: Form using + and . The current best upper bound for multiplying matrices is approximately Limitations of Strassens Algorithm From a practical point of view, Strassens algorithm is often not the method of choice for matrix multiplication, for the following four reasons: 1. The constant factor hidden in the running larger than the constant factor in the method. time of Stassens algorithm is
2. When the matrices are sparse, methods tailored for sparse matrices are faster.
3.
Stassens algorithm is not quite as numerically stable as the navemethod.4. The sub matrices formed at the levels of recursion consume space
Q.5 How do you formulize a greedy technique? Discuss the different steps one by one?
Ans 5 Set of Considered and Rejected Values:
As the name suggests, this is the set of all those values, which are considered but rejected. Let us call this set as RV : Set of considered and Rejected Values A candidate value may belong to both CV and RV. But, once a value is put in RV, then this value cannot be put any more in CV. For example, to make an amount of Rs. 289, once we have chosen two notes each of denomination100, we have CV = {100, 100}At this stage, we have collected Rs. 200 out of the required Rs. 289. At this stage RV = {1000, 500}. So, we can chose a note of any denomination except those in RV, i.e., except 1000 and 500. Thus, at this stage, we can choose a note of denomination 100. Selection Function Self Finds out the most promising candidate value out of the values not yet rejected. In the case of Minimum Number of Notes problem, for collecting Rs. 289, at the stage when RV = {1000, 500} and CV = {100, 100} then first the function Self attempts the denomination 100. But, through function Self, when it is found that by addition of 100 to the values already in CV, the total value becomes300 which exceeds 289, the value 100 is rejected and put in RV. Next, the function Self attempts the next lower denomination 50. The value 50 when added to the sum of values in CV gives 250, which is less than 289. Hence, the value 50 is returned by the function Self. The Feasibility-Test Function, say FeaF. When a new value say v is chosen by the function Self, then the function FeaF checks whether the new set, obtained by adding v to the set CV of already selected values, is a possible part of the final solution. Thus in the case of Minimum Number of Notes problem, if amount to be collected isRs. 289 and at some stage, CV = {100, 100}, then the function SelF returns50. At this stage, the function FeaF takes the control. It adds 50 to the sum of the values in CV, and on finding that the sum 250 is less than the required value 289 informs the main/calling program that{100, 100, 50} can be a part of some final solution, and needs to be exploredfurther.vii) The Objective Function, say ObjF, gives the value of the solution. For example, in the case of the problem of collecting Rs. 289; asCV = {100, 100, 50, 20, 10, 5, 2, 2} is such that sum of values in CV equals the required value 289, the function ObjF returns the number of notes in CV,i.e., the number 8.After having introduced a number of sets and functions that may be required by an algorithm based on greedy technique, we give below the outline of greedy technique, say Greedy-Structure. For any actual algorithm based on greedy technique, the various structures the functions discussed above have to be replaced by actual functions. These functions depend upon the problem under consideration. The Greedy-Structure outlined below takes the set GV of given values as input parameter and returns CV, the set of chosen values. For developing any algorithm based on greedy technique, the following function outline will be used.