Anda di halaman 1dari 13

KCG College of Technology

Chennai 600 097 Computer Science & Engineering Two Mark Questions and answers

Subject Code : CS 1201 Subject : Design and Analysis of algorithms - Unit-I


1. Define an Algorithm. An algorithm is a sequence of unambiguous instructions for solving a problem,i.e., for obtaining a requiered output for any legitimate input in a finite amount of time. 2. What is algorithmics?. Algorithmics is more than a branch of computer science. It is the core of computer science and ,in all fairness ,can be said to be relevant to most of science ,business ,and technology. 3. What is algorithm design technique? An algorithm design technique (or strategy or paradigm) is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing. 4. How is an algorithm's time efficiency is measured? The time efficiency is computed by 1) Measuring the input size If the input size is longer then algorithm runs for a longer time. 2) Measuring the running time - To measure the running time ,it is necessary to identify the basic operation of an algorithm and measure the time taken to execute the basic operation. 5. How an algorithm is specified? Algorithms can be specified using pseudocode which is a mixture of natural language and programming language like constructs. A pseudocode is more precise than a natural language,and often yields more succint algorithm descriptions. 6. What is correctness of algorithm? The algorithm's correctness is ascertained ,if the algorithm yields the requiered results for every legitimate input in a finite amount of time. 7. What are the two kinds of algorithm efficiency? The two kinds of algorithm efficiency are : Time efficiency which indicates how fast the algorithm runs. Space efficiency which indicates how much extra memory the algorithm needs. 8. What are important problem types?

The important problem types are Sorting Searching String processing Graph problems Combinatorial problems Geometric problems Numerical problems 9. What are fundamental data structures? Linear data structures Linked lists,stacks,queues Graphs Trees Sets and dictionaries 10. What is a graph? A graph G = (V,E) is defines by a pair of two sets: A finite set V of items called vertices and set E of pairs of these items called edges. 11. How a graph is represented? Graphs for computer algorithms are represented in two principal ways: the adjacency matrix and adjacency linked lists.

12. What is a Abstract Data type? It is a set of abstract objects with a collection of operations that can be performed on them. 13. What is an algorithm's basic operation? It is an operation that contributes the most to the total running time of the algorithm.Usually the basic operation is the most time consuming operation in the algorithm's inner most loop. what is the formula used to calculate the algorithm's running time? The running time T(n) of a program implementing the algorithm on a computer is given by the formula : T(n) = Cop x C(n) where Cop is the time of execution of an algorithm's basic operations C(n) is the the number of times the basic operation is executed. 15. What is the order of growth?

The Order of growth is the scheme for analyzing an algorithm's efficiency for different input sizes which ignores the multiplicative constant used in calculating the algorithm's running time. Measuring the performance of an algorithm in relation with the input size n is called the order of growth. 16. What is the worst-case efficiency of an algorithm? The worst-case efficiency of an algorithm is its efficiency for the worst-case input of size n,which is an input of size n for which the algorithm runs the longest among all possible inputs of that size. 17. List 5 of basic efficiency classes. log n n nlogn n2 2n logarithmic linear n-log-n quadratic exponential

18. What are asymptotic notations? Asymptotic notation is the short hand way to represent the time complexity. What is Big O Notation? Big O notation is the method of representing the upper bound of algorithm's running time. A function t(n) is said to be in O(g(n)),denoted by t(n) E O(g(n)),if t(n) is bounded above by some constant multiple of g(n) for all large n,i.e.,if there exists some positive constant c and some non negative integer n0 such that t(n) <= cg(n) for all n >= n0. What is L'Hopital's rule? lim n->oo t(n) -------g(n) Unit-1 Long questions Explain in detail the algorithm design and analysis process. Explain in detail the important problem types. Explain in detail the fundamental data structures. Write Euclid's algorithm and explain the steps. = lim t'(n) n->oo -------g'(n)

Write sieve of Eratosthenes algorithm which generates consecutive primes and explain. Explain in detail the general framework for analyzing an algorithm's efficiency. Explain with examples the worst-case,best-case and the average case effuieciencies. What are asymptotic notations? Define and explain the three notations used by computer scientists for analyzing the efficiency of algorithms. What are basic efficiency classes? Explain in detail. What is Order of growth? Plot the order of growth for different functions. Design and Analysis of Algorithms - Unit-2 What are recurrence relations? Consider the function M(n) = M(n-1) + 1 Here the equation defines M(n) not explicity ,i.e. as a function of n,but implicitly as a function of its value at another point,namely n-1. Such equations are called recurrence relations or recurrences. What is the method of backward substitution? Among several techniques available for solving recurrence relations,one of the method used is called the method of backward substitution. The method's idea will be clear by referring to the particular case as shown below : M(n) = M(n-1) + 1 for n > 0. M(0) = 0 = [M(n-2) + 1] + 1 = M(n-2) + 2 = [M(n-3) +1] + 2 = M(n-3) + 3 =M(n-n) + n = n. Write an algorithm for element uniqueness problem. ALGORITHM UniqueElements(A[0..n-1]) for I <-- 0 to n-2 do for j <-- i+1 to n-1 do if A[i] = A[j] return false return true

Write an algorithm for matrix multiplication problem. ALGORITHM MatrixMultiplication(A[0..n-1,0..n-1],B[0..n-1,0..n-1]) for i <-- 0 to n-1 do for j <-- 0 to n-1 do

C(i,j) <-- 0.0 for k <-- 0 to n-1 C(i,j) <-- C(i,j) + A[i,k] * B[k,j] retutn C Write an algorithm for finding the number of binary digits in the binary representation of a positive decimal integer. ALGORITHM Binary(n) count <-- 1 while n > 1 do count <-- count + 1 n <-- L n/2 _| return count Show the tree structure for recursive calls made in the problem of towers of Hanoi.

n n-1 n-2 2 1 1 n-2 n-2 2 1 1 n-1 n-2

2 1

...
1

...

...

2 1

Write an algorithm for finding the nth fibonacci number. ALGORITHM F(n) if n <= 1 return 1 else return F(n-1) + F(n-2) What is algorithm visualization? Algorithm visualization can be defines as the use of images to convey some useful information about algorithms. Two principal variations are Static algorithm visualization Dynamic Algorithm visualization(also called algorithm animation) What are the some of the desirable features of animation's user interface? Be consistent Be interactive Be clear and concise Be forgiving to the user Adapt to the knowledge level of the user.

Fibonacci numbers are obtainted by recursive calls. Draw a tree of recursive calls for fib(6).

Fib 5 Fib 3 Fib 1 1 Fib 1 1 Fib 2 Fib 0 0 Fib 0 0 Fib 4 Fib 2 Fib 1 1 1 Fib 3 Fib 1 Fib 0 0
Write a recursive algorithm for finding the factorial of a non negative integer. ALGORITHM F(n)

Fib 2

if n= 0 return 1 else return F(n -1) * n What is a scatter plot? Graphical representation of empirical data obtained as the result of an experiment is called a scatter plot. What is the principal alternative to the mathematical analysis of algorithm's efficiency? Empirical analysis It is done by running the algorithm on the sanple inputs and recorsing the data observed. Then the data is analysed and a scatter plot is prepared. What is the possible application of empirical analysis? One of the possibilities of the empirical analysis is to attempt predicting the algorithm's performance on the sample size not included in the experiment's sample. What is algorithm animation? Algorithm animation shows a continuous movie like presentation of an algorithm's operations. But this is more difficult to implement. What is the tool for analyzing the time efficiency of a non recursive algorithm? For analyzing the time efficiency of non recursive algorithm we need to find the input size as well as the basic operation of the algorithm. The execution of the basic operation depends upon the input size n. Then a sum is set up and is simplified using standard rules and formula.

What is linear congruent method? It is a well known algorithm for generating pseudo random numbers. ri <-( a * ri-1 + b) mod m

Differentiate : Mathematical and Empirical analysis. The algorithm is analyzed with the help The algoprithm is analysed by taking of mathematical derivations and there is some sample of input and no no need of specific input. mathematical derivation is involved The principal weakness is limited applicability The principal strength is it is independent of any input The principal strength is it is applicable for any algorithm The principal weakness is it depends upon the sample input

What is the principal strength of mathematical analysis of algorithms? The principal strength of mathematical analysis is its independence of specific inputs.

What is the principal strength of empirical analysis of algorithms? The principal strength lies in the applicability to any algorithm. Unit-2 Long questions Explain the general plan for analyzing efficiency of non recursive algorithms. Write an algorithm for element uniqueness problem and explain. Write an algorithm for matrix multiplication and explain Explain the general plan for analyzing efficiency of recursive algorithms. Explain the Tower of Hanoi puzzle and how the recurrence relation is solved for the moves. Write short note on algorithm visualization and its applications. Design a non recursive algorithm for computing the product of two nxn matrices and also find the time efficiency of the algorithm. Design a recurssive algorithm to compute factorial function f(n) = n! for an arbitrary non negative integer n and derive the recurrence relation. Discuss the features of animation of an algorithm. what is the empirical analysis of algorithm? Discuss its strength and weakness.

Design and analysis of algorithms - Unit-3 What is Brute force approach? Brute force is a straight forward approach to solving a problem,usually directly based on the problem's statement and definitions of the concepts involved.

Give some examples of Brute force approach? a) Selection sort b) bubble sort c) string matching

What is the principal strength of brute force approach? Wide applicability and simplicity

What are the general plan of divide and conquer strategy?

The problem's instance is divided into several smaller instances of the same problem,ideally about the same size. The smaller instances are solved typically recursively The solutions obtained for the smaller instances are combined to get a solution to the original problem.

How merge sort works? Merge sort is the sorting algorithm which uses the divide and conquer strategy. By this method the array is divided into two halves. These halves are sorted recursively. Then the sorted halves are merged to get the sorted array.

Explain the quick sort algorithm. Quicksort is based on the divide-and-conquer approach. Unlike mergesort,which divides its input's elements according to their position in the array,quicksort divides them according to their value. It rearranges elements of a given array A[0..n-1] to achieve its position,a situation where all elements before some positions 's' are smaller than or equal to A[s] and all the elements after position 's' are greater than equal to A[s] What is a pivot? In quicksort ,we partition the given array into two subarrays based on the value stored in the element called pivot. Give the time efficiency and drawback of mergesort algorithm. Time efficiency : The best,worst and average case time complexity of merge sort is O(nlogn) The drawbacks : (I) This algorithm requiers extra storage to execute this method (ii) This mehod is slower than the quick sort method (iii) This method is complicated to code. Explain briefly how binary search works. Binary search is remarkably efficient algorithm for searching in a sorted array.It works by comparing a search key 'K' with the array's middle element A[m].If they match,the algorithm stops;Otherwise,the same operation is repeated recursively for the first half of the array if K < A[m] and for the second half if K > A[m]. Write the Binary search algorithm. ALGORITHM BinarySearch(A[0..n-1],K) l <-- 0; r <-- n-1 while l <= r do m <-- |_ (I + r)/2_| if K = A[m] return m

else if K < A[m] r <-- m-1 else m <-- m + 1 return -1 What is the time complexity of binary search in worst case? Let the number of comparisons made in binary search algorithm = Cw(n) We have Cw(n) = Cw(|_n/2_|) + 1 for n > 1, Cw(1) = 1 = Cw(2k/2) + 1 = Cw(2k-1) + 1 = Cw(2k-2) + 2 Let n = 2k Then Cw(2k) = k + 1 log (n+1) What is a binary tree? A binary tree T is defines as a finite set of nodes that is either empty or consists of a root and two disjoint binary trees TL and TR called resp,the left and right sub tree of the root. Write a recursive algorithm for computing the height of a binary tree. ALGORITHM Height(T) //Input : A binary tree T //Output : The height of T if T = 0 return -1 else return max{Height( TL),Height( TR)} + 1 What is decrease-and-conquer technique? The decrease-and-conquer technique is based on exploiting the relationship between a solution to a given instance of a problem and solution to a smaller instance of the same problem.

What are the three major variations of the decrease-and-conquer technique? The three major variations of the decrease-and-conquer technique are Decrease by a constant decrease by a constant factor variable size decrease

Give an example of decrease by a constant Consider the exponentiation problem of computing an The relationship between a solution to an instance of size n and an instance of size n and instance of size n-1 is obtained by the obvious formula : an = an-1 . a So the function f(n) = an can be computed by using the recursive definition f(n) = | f(n-1) . a if n > 1 | a if n = 1

Give an example of variable size decrease gcd(m,n) = gcd(n,m mod n) In the above formula the arguments in the right hand side are always smaller than the left hand side. The right hand side decreases by a variable factor. Derive the worst case complexity of insertion sort. Cw(n) = (n-1)n/2 = O(n2)

Compare depth first search and depth first search. SNO 1 2 Depth first traversal uses stack data structure The DFS sequence is composed of tree edges and back edges the efficiency of adjacency matrix graph is O(V2) Breadth first traversal uses queue data structure The BFS sequence is composed of tree edges and cross edges the efficiency of adjacency matrix graph is O(V2)

What are the applications of depth first search? To check connectivity and acyclicity of graph To find articulation point Unit-3 Long questions 1)Write a pseudocode for divide and conquer algorithm for merging two sorted arrays into a single sorted one. Explain with an example. 2)Design a recursive decreae-by-one algorithm for sorting the n real numbers in an array with an example and determine the number of key comparisons and time efficiency of the algorithm.

3)Explain quick sort algorithm with an example. 4)Write an algorithm for Binary search tree and analyse its efficiency. 5)Give a suitable example and explain the breadth first search and depth first search algorithms. 6)Give an algorithm for selection sort. Analyze your algorithm's 7)Using the bruteforce string matching algorithm match the pattern EXAMPLE from the text This_IS_A_SIMPLE_EXAMPLE. 8)What is the principal idea behind decrease and conquer? Compare and contrast decrease and and conquer with divide and conquer approach. 9)Compare DFS and BFS. Explain in detail the general divide and conquer recurrence. Design and analysis of algorithms - Unit-4

Unit-4 Long questions 1)Define AVL tree. Explain the construction sequence of AVL tree with a simple example. 2)Define spanning tree. Discuss the design steps in Prim's algorithm to construct a minimum spanning tree with an example. 3)Construct a minimum spanning tree using Kruskal's algorithm with an example. 4)Solve the all pairs shortest path problem for the digraph with the weight matrix given below : 5)Give a suitable example and explain the breadth first search and depth first search algorithms. 6)Give an algorithm for selection sort. Analyze your algorithm's 7)Using the bruteforce string matching algorithm match the pattern EXAMPLE from the text This_IS_A_SIMPLE_EXAMPLE. 8)What is the principal idea behind decrease and conquer? Compare and contrast decrease and and conquer with divide and conquer approach. 9)Compare DFS and BFS. 10) Explain in detail the general divide and conquer recurrence. Design and analysis of algorithms - Unit-5 Unit-5 Long questions

1)Explain subset-sum problem and discuss the possible solution strategies using back tracking. 2)Discuss the solution for traveling salesman problem using brach and bound technique. 3)Solve the following instance of knapsack problem by branch-and-bound algorithm. ITEM 1 2 3 4 WEIGHT 4 7 5 3 VALUE $ 40 $42 $25 $12

The knapsack capacity W = 10 4)Differentiate between back tracking and branch-and-bound methods. 5)Construct a state-space-tree and solve the 4 queen problem. 6)Explain with an example the Hamiltonian circuit problem. 7)Explain with an example the assignment problem. 8)Write an algorithm Backtrack and explain. 9)Apply backtracking technique to solve the following instance of the subset sum problem. S = {1,3,4,5} and d = 11. 10)Write short notes on a)back tracking b) Branch and bound c) State space tree d)promising and non promising nodes

Anda mungkin juga menyukai