# CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers

UNIT 1 1. Define Algorithm. An algorithm is a sequence of unambiguous instructions for solving a problem, which means to obtain a required output for any legitimate input in a finite amount of time. 2. What are the characteristics of an algorithm? · Simplicity · Generality · Definiteness · Finiteness · Effectiveness 3. What are three parts of algorithm? · Pre Condition · Body of Algorithm · Post Condition 4. What is Algorithm Design Technique? An algorithm design technique is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing. 5. What are the criteria used to identify the best algorithm? · Order of Growth · Time Complexity · Space Complexity 6. Define time and space complexity. Time Complexity indicates how fast an algorithm runs. T(P)=Compile Time+ Run Time .(Tp) Where Tp is no of add, sub, mul... Space Complexity indicates how much extra memory the algorithm needs. Basically it has three components. They are instruction space, data space and environment space. 7. Difference between Compile and Running Time.

Dept. of CSE, SVSCE

CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers

8. Find the time complexity for summation of N numbers. The time complexity for summation of N numbers is O (N). 9. What are the various types of time complexity of an algorithm? · Big Oh · Big Omega · Big Theta · Little Oh · Little Omega 10. Why is the need of studying algorithms? From a practical standpoint, a standard set of algorithms from different areas of computing must be known, in addition to be able to design them and analyze their efficiencies. From a theoretical standpoint the study of algorithms in the cornerstone of computer science. 11. What is algorithmics? The study of algorithms is called algorithmics. It is more than a branch of computer science. It is the core of computer science and is said to be relevant to most of science, business and technology. 12. What are the fundamental steps involved in algorithmic problem solving? The fundamental steps are: 1) Understanding the problem 2) Ascertain the capabilities of computational device 3) Choose between exact and approximate problem solving 4) Decide on appropriate data structures 5) Algorithm design techniques 6) Methods for specifying the algorithm 7) Proving an algorithms correctness 8) Analyzing an algorithm 9) Coding an algorithm 13. What are the steps involved in the analysis framework? The various steps are as follows. 1) Measuring the input¶s size 2) Units for measuring running time 3) Orders of growth 4) Approaches in analysis of algorithms 5) Worst case, best case and average case efficiencies

Dept. of CSE, SVSCE

CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 14. SVSCE . Ex: if you want to sort a list of numbers in ascending order when the numbers are given in ascending order. In this running time will be the smallest.but the total time for an entire sequence of n such operations is always significantly better than the worst case efficiency of that single operation multiplied by n. What do you mean by tWorst case-Efficiency´ of an algorithm? The tWorst case-Efficiency´ of an algorithm is its efficiency for the worst-case input of size n. Dept. for which the algorithm runs between the best case and the worst case among all possible inputs of that size. What do you mean by ³Amortized efficiency´? The ³Amortized efficiency´ applies not only a single run of an algorithm but rather to a sequence of operations performed on the same data structure. What do you mean by tBest case-Efficiency´ of an algorithm? The tBest case-Efficiency´ of an algorithm is its efficiency for the Best-case input of size n. 19. 17. Example: It will be the size of the list for problems of sorting. What are the basic asymptotic efficiency classes? The various basic efficiency classes are: 1) Constant: 1 2) Logarithmic: log n 3) Linear: n 4) N-log-n: nlogn 5) Quadratic: n2 6) Cubic: n3 7) Exponential: 2n 8) Factorial: n! 15. searching. of CSE. 16. Define the tAverage-case efficiency´ of an algorithm? The tAverage-case efficiency´ of an algorithm is its efficiency for the input of size n. This is known as ³Amortized efficiency´. which is an input (or inputs) of size n for which the algorithm runs the longest among all possible inputs of that size. 18. It turns out that in some situations a single operation can be expensive . which is an input(or inputs) of size n for which the algorithm runs the fastest among all possible inputs of that size. and most other problems dealing with lists. Ex: if you want to sort a list of numbers in ascending order when the numbers are given in descending order. In this running time will be the longest. How to measure the algorithm¶s efficiency? It is logical to investigate the algorithm¶s efficiency as a function of some parameter n indicating the algorithm¶s input size. finding the list¶s smallest element.

A. The worst case complexity of an algorithm is its efficiency for the worst case input of size N. Then we can estimate the running time T(n) of a program implementing this algorithm on that computer by the formula T(n) § Cop C(n) 22.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 20. The best case complexity of an algorithm is its efficiency for the best case input of size N. 21. B. SVSCE . Big Omega. 26.  (Big Omega) notation & iii. The efficiency analysis framework concentrates on the order of growth of an algorithm¶s basic operation count as the principal indicator of the algorithm¶s efficiency.C. What is called the basic operation of an algorithm? The most important operation of the algorithm is the operation contributing the most to the total running time is called basic operation of an algorithm. How to measure an algorithm¶s running time? Let Cop be the time of execution of an algorithm¶s basic iteration on a particular computer and let C (n) be the number of times this operation needs to be executed for this algorithm. (Big Theta) notation 23. What are the 3 standard notations? a) Big Oh(O) b) Big Omega( ) c) Big Theta( ) Dept. 24. } Space Complexity = Space Needed For P. The efficiency analysis framework concentrates on the order of growth of an algorithm¶s basic operation count as the principle indicator of the algorithm¶s Efficiency. Define order of growth. printf(³%d´. which is an input of size N for which the algorithm runs fastest among all possible inputs of that size. P=A+B-C. which is called as asymptotic notation. and Big Theta. To compare and rank such orders of growth scientists¶ use three notations (Big Oh. C = 8 25. Define asymptotic notation. of CSE. Difference between Best Case and Worst Case Complexities. O (Big oh) notation ii.A. which is an input of size N for which the algorithm runs longest among all possible inputs of that size. To compare and rank such orders of growth we use three notations i. P).B. What is the Space Complexity for the following algorithm? void N() { int P.

if t(n) is bounded below by some positive constant multiple of g(n) for all large n. i. What is the use of Asymptotic Notations? The notations O..e.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 27. What Are The Common Running Time For Big-Oh. 31.. if t(n) is bounded both above and below by some positive constant multiples of g(n) for all large n. i. of CSE. if there exist some positive constant c and some non negative integer n0 such that T (n) < c g (n) for n > n0 28. Such equations are called recurrence relation. but implicitly as a function of its value at another point. denoted t(n)  (g(n)). The equation defines M (N) not explicitly. 29. Define Conditional Asymptotic Notation. Define Big oh notation A function t(n) is said to be in O(g(n)) denoted t(n) O (g(n)).. Let F be an eventually nonnegative sequence of real numbers and Let X be a set.. if t(n) is bounded above by some constant multiple of g(n) for all large n. If T(N) (F(N)) For Values Of N That Are Powers Of B. Where B>=2. namely N-1. The common running time for Big-Oh Are · O(N) · O(Log N) · O(N Log N) · O(N^C). 33. F(N) is called Smooth If it is eventually non decreasing and F(2n) (F(N)). denoted t(n)   (g(n)). Dept. Let F (N) be a nonnegative function defined on the set of natural numbers. if there exist some positive constant c1 and c2 and some non negative integer n0 such that c2 g (n) < t (n) < c1 g(n) for n > n0 30. Define Recurrence Relation. and 5 and are used to indicate and compare the asymptotic orders of growth of functions expressing algorithm efficiencies. Define Smoothness Rule. . The function O(F|X) yields a non empty set of functions from N to R and is defined as follows: 32.e. i..notation A function t(n) is said to be in (g(n)).e. Define  notation A function t(n) is said to be in  (g(n)). if there exist some positive constant c and some non negative integer n0 such that T (n) < c g (n) for n > n0 Define . Let T(N) be an eventually a non decreasing function and F(N) be a smooth function. SVSCE .C>1 34. Then T (N) (F(N)) For Any N. is a function of n. ie.

linear search or sequential search is a method for finding a particular value in a list. for the number of times basic operation is executed. Substitution method is a method of solving a system of equations wherein one of the equations is solved for one variable in terms of the other variables. · Identify the algorithms Basic Operation · Check whether the number of times the basic operation is executed only on the size of an input. What are the Best. the worst case. and if necessary. The relation is read as "f(x) is little-o of g(x)". best case efficiencies have to be investigated separately. · Set up a recurrence relation. SVSCE . it means that g(x) grows much faster than f(x). Intuitively. 40. Worst and Average Case complexity of Linear Search? · Best Case ± O (1) · Average Case ± O (N) · Worst Case ± O (N) 38. f(n) and g(n).CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 35. c > 0. then O(n^d) if a < b^d T(n) = O(n^d log n) if a = b^d O(n^logb a) if a > b^d 41. If it also depends on some additional property. Dept. Let T(n) be a monotonically increasing function that satisfies T(n) = aT(n/b ) + f(n) T(1) = c where a  1. It assumes that f and g are both functions of one variable. Give Master Theorem. which consists in checking every one of its elements. If f(n) O(n^d) where d  0. 39. with an appropriate initial condition. average case. Formally. Give the general plan for analyzing recursive algorithm. b  2. until the desired one is found. one at a time and in sequence. of CSE. Define Linear Search. but f(n)  (g(n)). f(n) is little omega of g(n) if and only if f(n) = _(g(n)). · Decide a parameter indicating an Input¶s Size. Define Little Oh and Little Omega Notations. it states For non-negative functions. This is denoted as "f (n) = (g (n))". 37. Define Substitution Method. In computer science. What are all the types of recurrence relation? · Geometric sequence · Arithmetic sequence · Linear sequence 36.

and if necessary. of CSE. Define Data Space. y The values of all local variables. y The return address. · Data Space: The space needed to store all constants and variable values. 43. · Instruction Space: The space needed to store the compiled version of all program instruction · Environment Space: The environment stack is used to save information needed to resume execution of partially completed functions. average case. · Using standard formulas and rules of sum manipulation either find a closed formula for the count or. Instruction Space and Environment Space. · Identify the algorithms Basic Operation · Check whether the number of times the basic operation is executed only on the size of an input. 44. at the very least. · Sorting · Searching · String Processing · Graph Problem · Combinational Problem · Geometric Problem · Numerical Problem 46. Dept. · Non homogeneous recurrence relation. What are the types of recurrence relations? · Homogeneous recurrence relation. best case efficiencies have to be investigated separately. SVSCE . · Decide a parameter indicating an Input¶s Size. If it also depends on some additional property. Each time a function is invoked the following data are saved the environment stack. establish its order of growth. Give the general plan for analyzing non recursive algorithm. Write down the problem types. What are all the methods available for solving recurrence relations? · Forward Substitution · Backward Substitution · Smoothness Rule · Master Theorem 45.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 42. the worst case.

Q) //the data size is from p to q { if size(P. A divide and conquer algorithm works by recursively breaking down a problem into two or more sub-problems of the same (or related) type. Find the number of comparisons made by the sequential search in the worst case and the best case. until these become simple enough to be solved directly.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers UNIT 2 1.Q)) } Sometimes. Q) Combine (D&C(P. CooleyTukey fast Fourier transform (FFT) algorithm and merge sort algorithm. 4. What are the objectives of sorting algorithms? The objective of the sorting algorithm is to rearrange the records so that their keys are ordered according to some well-defined ordering rule. An optimization problem is a computational problem in which the object is to find the best of all possible solutions. The control abstraction for D&C technique is as follows: procedure D&C (P. Some of the examples of D&C method are binary search. Dept. Give some examples of divide and conquer method. this type of algorithm is known as control abstract algorithms as they give an abstract flow. 5. The numbers of comparisons made by the sequential search in the worst and best case are one and n key comparisons respectively. 3. Divide and conquer (D&C) is an important algorithm design paradigm based on multibranched recursion.Q) is small Then solve (P. SVSCE . Euclidean algorithm. of CSE. 7. selection and searching algorithm. More formally. The solutions to the sub-problems are then combined to give a solution to the original problem. What is the order of an algorithm? A standard notation used to represent the computing time of the algorithm is termed as the order of an algorithm and is denoted by O. 2. This way of breaking down the problem has found wide application in sorting. What is meant by optimal solution? A solution to an optimization problem which minimizes (or maximizes) the objective function is termed as an optimal solution. Write control abstraction for D&C technique. Define divide and conquer strategy.Q) else M divide (P. 6.M). find a solution in the feasible region which has the minimum (or maximum) value of the objective function. D&C(M+1.

16. 10. 15. What are all the advantages of Binary search? The Binary search is an optimal searching algorithm using us can search the desired element effectively. What is the time complexity of straight forward with D & C of finding Min-max? · Best case occurs when the elements are in increasing order. SVSCE . the search is finished. 13. An optimal solution is a feasible solution that optimizes the objective/optimization function. of CSE. Binary search is a fast way to search a sorted array. If the key is equal to that. · Feasible ()-is a Boolean-valued function that determines whether x can be included into the solution vector. so the number of element comparisons is n · Worst case occurs when the elements are in decreasing order. Advantages of binary search. finding an optimal solution is computationally hard. Define feasible solution. do a binary search of the second half. Dept. · Average case occurs when a[i] is greater than max half the time. In general. Applications: The binary search is an efficient searching method & is used to search desired record from database. Define optimal solution. For solving nonlinear equations with one unknown this method is used. If the key is less than the middle element. If it's greater. Define greedy technique The greedy method is the most straight forward design technique that can be applied to a wide variety of problems. so the number of element comparisons is 2(n-1). 9. · Union ()-is the function that combines x with the solution and updates the objective function. What is the time complexity of binary search? Best Case Average Case Worst Case O(1) O(log2n) O(log2n) 11. 12. What is the Control abstraction of greedy technique? · Select ()-is the function that selects an input from a [] and removes it. do a binary search on the first half. The idea is to look at the element in the middle. A feasible solution is a solution that satisfies the constraints 14. What is meant by Container-loading? Container-loading problem is a problem which is used to load the ship with the maximum number of containers.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 8.

SVSCE . General plan for divide & conquer algorithm: · Divide the problem into two or smaller sub problems · Conquer the sub problems by solving them recursively · Combine the solutions to the sub problems into the solutions for the original problem. complexity classes can be defined based on function problems. However. It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most useful items. counting problems. determine the number of each item to include in a collection so that the total weight is less than a given limit and the total value is as large as possible. · Locally optimal-among all feasible solutions the best choice is to be made Irrevocableonce the particular choice is made then it should not get changed on subsequent steps. Define a knapsack problem. etc. etc. monotone circuits. · A complexity class is a set of problems of related complexity. etc. each with a weight and a value.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 17. · Knapsack problem. such as "polynomial time". optimization problems. · The resources (or resources) that are being bounded and the bounds: These two properties are usually stated together. 18. · Feasible-it should the problem's constraints.. of CSE. Dept. The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items. but many complexity classes are based on nondeterministic Turing machines. How the choices are made in each step in greedy method: · Choices of solution made at each step of problem solving in greedy approach is as follows. Boolean circuits. 20. "logarithmic space". Simpler complexity classes are defined by the following factors: · The type of computational problem: The most commonly used problems are decision problems. 21. · Bipartite cover · Single-source shortest paths · Minimum-cost spanning trees 19. quantum Turing machines. Define Complexity Analysis. "constant depth". · Topological sorting.. · The model of computation: The most common model of computation is the deterministic Turing machine. promise problems. Application of greedy algorithm: · Container loading.

CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers UNIT 3 1. table structure and bottom up computations. 4. What is dynamic programming? Dynamic programming is an algorithm design method. A problem is said to have optimal substructure if the globally optimal solution can be constructed from locally optimal solutions to sub problems. It avoids the calculation of same stuff twice. We can either build up solutions of sub-problems from small to large (bottom up) or we can save results of solutions of sub-problems in a table (top down + memorization). Dept.This forms the table structure. where the solution to the main problem can be viewed as the result of a sequence of decisions. What are the basic elements of dynamic programming? · Sub structure · Table structure · Bottom up computations 5. of CSE. SVSCE . What is the difference between dynamic programming and greedy algorithm? 2. What is the difference between dynamic programming and divide and conquer? 3. by keeping the table of known results of sub-problems. Define sub structure.

j> ! E 10. Each set Vi is called a stage in the graph.t> ! E Backward approach Bcost(i. A multistage graph is a graph o G=(V.j)+cost(i+1.j)= . o and | V1 | = | VK | = 1. The vertex s in V1 is called the source.E) with V partitioned into K >= 2 disjoint subsets such that if (a.j) if <1. <l. then a is in Vi .b) is in E. <j. if<I.bcost(2.j> E since.j) of multistage graph in both forward and backward approach.l> E. the vertex t in VK is called the sink.t>  E and cost (k-1. What are the applications of dynamic programming? · Fibonacci numbers · Longest increasing sequence · Minimum weight triangulation · The partition problem · Appropriate string matching 7. E and Dept.t). and b is in Vi+1 for some subsets in the partition.l)+c(l.j)=c(j.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 6. To use dynamic programming the problem must observe the principle of optimality that whatever the initial state is. Forward approach Cost(i. remaining decisions must be optimal with regard the state following from the first decision.j)=min{bcost(i-1. Since. 8.j> bcost(2. Explain All-pair shortest-paths problem Given a weighted connected graph (undirected or directed). Define multi stage graph. the all pairs shortest paths problem asks to find the distances (the lengths of the shortest path) from each vertex to all other vertices. The cost of a path from node v to node w is sum of the costs of edges in the path. Give the formula for cost (i. The "multistage graph problem" is to find the minimum cost path from s to t. G is usually assumed to be a weighted graph. each sub sequence must be optimal. SVSCE . Define the principle of optimality.l)} l vi+1 (vertex in next stage) . if <j. of CSE. cost (k-1. It states that in an optimal sequence of decisions.j)=c(1. 9.j)=  if<1.j)} l vi-1 .j)=min{c(i.

Dept. in which the element in the ith row (1<i<n) and the jth column (l<j<n) is 1 if there exists a non trivial directed path from the ith vertex to jth vertex .. What are the preconditions for the Floyd¶s algorithm? The precondition for the Floyd¶s algorithm is that the graph should not have a cycle of negative length or cost. R(n) Each of these matrices provides certain information about directed paths in the digraph. The name "binomial coefficients" comes from the participation of these numbers in the so called binomial formula (a+b)n =(n. Derive the formula for the Floyd¶s algorithm and running time of the algorithm.}. It is called Floyd's algorithm.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 11. Define Binomial Coefficient The Binomial Coefficient... Explain Floyd's algorithm It is convenient to record the lengths of shortest paths in an n by n matrix D called the distance matrix: the element dij in the ith row and the jth column of this matrix indicates the length of the shortest path from the ith vertex to the jth vertex . NOTE: Draw the graph given in class notes.. R(k-l)R(k)... 15.. Explain Warshall¶s algorithm Warshall's algorithm constructs the transitive closure of a given digraph with n vertices through a series of n by n Boolean matrices R(0).n)bn 16. Define Transitive closure The transitive closure of a directed graph with n vertices can be defined as the n by n Boolean matrix T = {ti... 13. «««. for k<--1 to n do for i<--1 to n do for j<--1 to n do D[i.k]+D[k. tij is 0. denoted C(n..+C(n.««..j].k) is the number of Combinations(subsets) of k elements from an n-element set(0<k<n). SVSCE .j]} RUNNING TIME OF THE ALGORITHM: O(n3) 14.j]=min{[i.+C(n. What does Floyd¶s algorithm do? It is used to find the distances (the lengths of the shortest paths) from each vertex to all other vertices of a weighted connected graph.. We can generate the distance matrix with an algorithm that is very similar to warshall's algorithm.. 17.. 12.. otherwise . of CSE..0)an+.D[i..i)ani i b +.

n]. Given a list of cities and their pair wise distances. Define OBST. 22. of CSE. Mathematically the 0-1-knapsack problem can be formulated as: 23. The most common formulation of the problem is the 0-1 knapsack problem. Dept. · Develop a recurrence relation that is a solution to its sub solution using mathematical notation in step 1. If probabilities of searching for elements of a set are known. · Prove the principle of optimality. Define 0/1 Knapsack problem. · Write an algorithm to compute the recurrence relation. One of the principal applications of Binary Search Tree is to implement the operation of searching. What is the running time of traveling salesman problem and 0/1 knapsack problem? TSP: 0(n2 * 2n) 0/1 Knapsack: 0(nw) 21. The k values the entries in the main table is entered into the root table. 20. What are the steps involved in dynamic programming? · Develop a mathematical relation that can express any solution and sub solutions for problem. An OBST is a BST which has minimal expected cost. which restricts the number xi of copies of each kind of item to zero or one. 19. What is meant by TSP? The Traveling Salesman Problem (TSP) is a problem in combinatorial optimization studied in operations research and theoretical computer science. Criterion for an optimal tree: Each optimal binary search tree is composed of a root and (at most) two optimal sub trees. The root value is given by R [1. SVSCE . the task is to find a shortest possible tour that visits each city exactly once. What is root table? The root table is a table which has 0 to n columns and 1 to n+ 1 row. it is natural to pose a question about an optimal binary search tree for which the average number of comparisons in a search is the smallest possible. the left and the right.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 18. It is one of the most intensively studied problems in optimization.

SVSCE . Backtracking is to build up the solution vector one component at a time and to use modified criterion function Pi(x1.«..xn) where xi are chosen from some set Si. · If |Si|=mi. · Optimization problem: .Whether there exists any best solution.mn candidates are possible · Yielding the same answer with far fewer than m trials · Advantage : if it is realized that the partial vector (x1. Constraint satisfaction problem Dept. 2.. in the top-down fashion but only once. UNIT 4 1.x2..´ 4. It suggests generating each and every element of the problem¶s domain.Whether there is any feasible solution.. 3. of CSE.. selecting those of them that satisfy the problem¶s constraints. Graph coloring. Difference between Backtracking & Exhaustive search.. and then finding a desired element.xi) (sometimes called bounding function) to test whether the vector being formed has any chance of success. · Decision¶s problem: . N-Queens problem. List down the examples of backtracking. Subset-Sum problem. Exhaustive search is simply a ³brute ± force´ approach to combinatorial problems. m=m1m2.xi) can in no way lead to an optimum solution.. Desired solution expressed as an ntuple (x1. Define Backtracking. just necessary sub problems of a given problem and recording their solutions in a table. Hamiltonian circuit problem. Give the categories of the problem in backtracking.Finds all possible feasible solution. 5. It does this by solving. Explain the Memory Function technique The Memory Function technique seeks to combine strengths of the top down and bottom-up approaches to solving problems with overlapping subproblems. then mi+1«mn possible test vectors can be ignored entirely.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 24. · Enumeration problem: . Define exhaustive search.

ALGORITHM Backtrack(X[1.i+1]) 11. SVSCE . the tree is called a state space tree. · Non ± Promising node: A node in a state space tree is said to be non-promising if it corresponds to a partially constructed solution that would not be able to lead to a complete solution further.... Explain State Space Tree If it is convenient to implement backtracking by constructing a tree of choices being made. of CSE. Explicit constraints are rules that restrict each xi to take on values only from a given set. · Implicit constraints are rules that determine which of the tuples in the solution space of I that satisfy the criterion function.i] specifies the first I promising components of a solution //Output All the tuples representing the problem¶s solution if X[1.i]) //Gives a template of a generic backtracking algorithm //Input X[1. Define promising and non promising node. Define implicit constraint.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 6.. 7. · Implicit constraints describe the way in which the x is must relate to each other. Give a template for a generic backtracking algorithm. · Explicit constraints depend on the particular instance I of problem being solved · All tuples that satisfy the explicit constraints define a possible solution space for I · Examples of explicit constraints 10.i] is a solution write X[1. Dept. · Promising Node: A node in a state space tree is said to be promising if it corresponds to a partially constructed solution that may still lead to a complete solution. Define explicit constraint.i] and the constraints do X[i+1] Å x Backtrack(X[1. 9.. What are the two types of constraints used in Backtracking? · Explicit constraints · Implicit constraints 8..i] else for each element xÎSi+1 consistent with X[1. Its root represents an initial state before the search for a solution begins.

If such an element does not exist. How can the output of a backtracking algorithm be thought of? The output of a backtracking algorithm can be thought of as an n-tuple (x1. 18. the current form of the game emerged in Southern Europe in the second half of the 15th century after evolving from similar. 15. Explain promising and nonpromising node A node in a state space tree is said to be promising if it corresponds to a partially constructed solution that may still lead to a complete solution. the algorithm finds the next element in Si+1 that is consistent with the values of (x1. Mention two reasons to terminate a search path at the current node in a state-space tree of a branch and bound algorithm. Define Feasible Solution A feasible solution is a point in the problem's search space that satisfies all the problem's constraints. If such a tuple (x1._Exploit the symmetry often present in combinatorial problems. What is Chess? Chess is a recreational and competitive game for two players. of CSE. The node represents no feasible solutions because the constraints of the problem are already violated. Ex: A Hamiltonian Circuit in the traveling salesman problem. much older games of Indian origin. y Preassign values to one or more components of a solution y Rearranging the data of a given instance. «xi) and the problem¶s constraints and adds it to the tuple as its (I+1)st coordinate. What are the tricks used to reduce the size of the state-space tree? The various tricks are . and so on. 19. «xn) where each coordinate xi is an element of some finite linearly ordered set Si. Define optimal solution Is a feasible solution with the best value of the objective function? Eg: The shortest Hamiltonian Circuit The most valuable subset of items that fit the knapsack 17. the algorithm backtracks to consider the next value of xi. «xi) is not a solution. Sometimes called Western Chess or International Chess to distinguish it from its predecessors and other chess variants. Dept. SVSCE . otherwise it is called nonpromising 13.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 12. So some solutions can be obtained by the reflection of others. Explain n-Queens problem The problem is to place n queens on an n by n chessboard so that no two queens attack each other by being in the same row or same column or on the same diagonal. A subset of items whose total weight does not exceed the knapsack's Capacity 16. This cuts the size of the tree by about half. The value of the node's bound is not better than the value of the best solution seen so far. 14.

«. n/2£ i£ n can be obtained by reflection from a solution with the first queen in square (1. The node can be terminated as a non-promising node if either of the two equalities holds: 26. Explain Subset-Sum Problem We consider the subset-sum problem: Find a subset of a given set S={S1. When can a node be terminated in the subset-sum problem? The sum of the numbers included are added and given as the value for the root as s¶. x2. How can you represent the solution for 2 queen¶s problem? There is no solution for 2 Queen¶s problem since however the queens are arranged both queens would be in same diagonal or column. Define problem state? · Problem state is each node in the depth-first search tree Dept..8} o Implicit constraints  No two xi¶s can be the same column or row (By this. Placements in the last n/2 columns need not be considered. 25. x8) where xi is the column on which queen ³i´ is placed.Sn} of n positive integers whose sum is equal to a given positive integer d.S2.. SVSCE .CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 20. Draw the solution for the 4-queen problem 21.. o Explicit constraints  Si={1. Constraints are..2. What is the method used to find the solution in n-queen problem by symmetry? The board of the n-queens problem has several symmetries so that some solutions can be obtained by other reflections. solution space reduced from 88 to 8!)  No two queens can be on the same diagonal 24.. n-i+1) 22. 23...«.. of CSE. i).. How can you represent the solution for 8 queen¶s problem? All solutions represented as 8-tuples (x1. because any solution with the first queen in square (1..

j) and (k. . SVSCE . UNIT 5 1. The color of each node is indicated next to it.vn is a Hamiltonian path if every vertex of the graph occurs exactly once in this path. · This process is repeated until no more vertexes is left 4. It starts at initial vertex and visits each and every vertex exactly once and finally reaches end vertex. Searching a vertex in a graph can be solved by starting at vertex V and systematically searching the graph G for vertices that can be reached from V. 3. of CSE. Dept. State the equation which is used to represent 2 queens are in same diagonal.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers for which the graph G can be colored. Let the diagonals be (i. Moreover. · Then it visits next unvisited vertex. This integer is referred to as the chromatic number of the graph. 2. What is the time complexity of BFS? · If the graph is represented by adjacency matrix: O (n2). 36. Define graph traversal. What is meant by BFS traversal? · It starts from the arbitrary vertex.l) The equation to represent 2 queens are in same diagonal is i+j=k+l j-l=k-I or i-j=k-l j-l=i-k 38. Explain Knapsack Problem Find the most valuable subset of n items of given positive integer weights and values that fit into a knapsack of a given positive integer capacity. · Depth first search traversal. . We say that a path v1. Mention the types of traversal. If three colors are needed to color the graph then the graphs chromatic number is 3. · It visits all vertices adjacent to starting vertex. · If the graph is represented by adjacency List: O (|V|+ |E|). then the path is called a Hamiltonian circuit 37. if the last vertex of the path duplicates the first one without ever repeating any other vertex in between. v2.E) that is undirected. · Breath first search traversal. Suppose we are given a graph G = (V. Define Hamiltonian circuit problem.

· If the graph is represented by adjacency List: O (|V|+ |E|). 8. Write pseudo code for BFS? 1 procedure BFS (Graph. Compare DFS and BFS. What is the time complexity of DFS? · If the graph is represented by adjacency matrix: O (n2). Cheney's algorithm Finding the shortest path between two nodes u and v Testing a graph for bipartiteness (Reverse) Cuthill±McKee mesh numbering Ford±Fulkerson method for computing the maximum flow in a flow network Serialization/Deserialization of a binary tree vs serialization in sorted order. allows the tree to be re-constructed in an efficient manner Dept. Define depth first search traversal. 6. SVSCE . What are the applications of BFS? y y y y y y y Finding all nodes within one connected component Copying Collection. of CSE. 7.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 5. · It starts from the arbitrary vertex. source): 2 create a queue Q 3 enqueue source onto Q 4 mark source 5 while Q is not empty: 6 dequeue an item from Q into v 7 for each edge e incident on v in Graph: 8 let w be the other end of e 9 if w is not marked: 10 mark w 11 enqueue w onto Q 9. · The exploration of the vertex V is suspended as soon as a new vertex is reached · At this time the exploration of new vertex U begins · The new vertex is explored the exploration of V continues · The search terminates when all reached vertices have been fully explored.

Finding 2-(edge or vertex)-connected components. Em) be its connected components. 13.incidentEdges (v) do 4 if edge e is unexplored then 5 w G. Further. of CSE. Topological sorting.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 10. 1 procedure DFS (G... · A spanning tree is a minimal sub graph. G'. e) 6 if vertex w is unexplored then 7 label e as a discovery edge 8 recursively call DFS (G. SVSCE . Planarity Testing Solving puzzles with only one solution. for all i  j. y A connected component is the maximal sub graph of a given graph. of G such that V (G') = V (G) and G' is connected · A minimal sub graph is one with the fewest no. Vi Vj=ø. that is.opposite (v. Define connected component.. E1). such as mazes. 14. Define spanning tree. formally.. of edges · Any connected graph with n vertices must have at least n -1edges. Em. V=V1 . E) be a graph and G1=(V1. Gm=(Vm. y A graph is said to be connected if for every pair of its vertices U and V. Vm and E=E1 .... y The set of maximally connected components of an undirected graph y Let G=(V. and all connected graphs with n -1 edges are trees · A spanning tree has n -1 edge Dept.. Write pseudo code for DFS..) Maze generation may use a randomized depth-first search. (DFS can be adapted to find all solutions to a maze by only including nodes on the current path in the visited set. · Sub graph formed by the vertices on this list make up a connected component. Finding strongly connected components. What are the applications of DFS? y y y y y y y y Finding connected components. v): 2 label v as explored 3 for all edges e in G. the components partition (1) V. Finding biconnectivity in graphs 12. w) 9 else 10 label e as a back edge 11. How do identify connected component using breath first search? · BFS can be used to determine whether G is connected · Using BFS all newly visited vertices are put on the list. Every vertex is in exactly in one connected component. there is path from U to V.

23.It works by attaching to a previously constructed subtree a vertex to the vertices already in the tree. Dept.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 15. That is.E) as an acyclic subgraph with | V| . produces a graph. What are the methods to identify the articulation point? · Common vertex in bi connected component · Depth first spanning tree · Lowest depth first number 22. G'. we compute the L(u) that is reachable from V by taking zero or more edges and then possible one back edge.1 edges for which the sum of the edge weights is the smallest. Define Minimum Spanning Tree A minimum spanning tree of a weighted connected graph is its spanning tree of the smallest weight. 16. 17. whenever a new unvisited vertex is reached for the first time. What is meant by articulation point? An articulation point is a vertex v of G such that the deletion of v. SVSCE . 18. that has at least two connected components 19. · A bi connected graph is a connected graph that has no articulation points · A bi connected component of a connected undirected graph is a maximal bi connected sub graph of G 20. of CSE. What are biconnected components? A maximal subset of edges of a connected graph such that the corresponding induced subgraph cannot be disconnected by deleting any vertex. that is noted as a cross edge. If an edge is leading to a previously visited vertex other than its immediate predecessor. What is tree edge and cross edge? In the breath first search forest. it is attached as a child to the vertex from which it is being reached. Define bi connected graph and bi connected component. the subgraph is biconnected or has no cut vertex 21. where the weight of a tree is defined as the sum of the weights on all its edges. What is meant by lowest depth first number? For every vertex V in depth first spanning tree. Such an edge is called tree edge. Define Prim's Algorithm Prim's algorithm is a greedy algorithm for constructing a minimum spanning tree of a weighted connected graph. together with all edges incident on v. Define Kruskal's Algorithm Kruskal's algorithm looks at a minimum spanning tree for a weighted connected graph G =(V.

· e-node is a live node whose children are currently being explored. SVSCE .CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 24. List down the bi connected components for the following connected graph. In other words. Dept. of CSE. e node and dead node. · Live node is a node that has been generated but whose children have not yet been generated. Define branch and bound. Define live node. All children of a dead node have already been expanded. Connected graph is 25. Branch-and-bound refers to all state space search methods in which all children of an Enode are generated before any other live node can become the E-node. 26. · Dead node is a generated node that is not to be expanded or explored any further. an enode is a node currently being expanded.

Heuristic is based on the expected additional computational effort (cost) to reach a solution from the current live node. Compare the FIFO and LIFO search. of CSE. Let Ög(x) be an estimate of the additional effort needed to reach an answer from node x. Explain the halting problem Given a computer program and an input to it. Ex: Going to the nearest unvisited city in the traveling salesman problem is a good illustration for Heuristic Dept. determine whether the program will halt on that input or continue working indefinitely on it. Such problems are called Undecidable. and if the decision problems cannot be solved at all by any algorithm. Define tractable and intractable problems Problems that can be solved in polynomial time are called tractable problems. What is meant by Least Cost Search? The next E-node is selected on the basis of this ranking function. Explain the theory of computational complexity A problem's intractability remains the same for all principal models of computations and all reasonable input encoding schemes for the problem under consideration 33. SVSCE .) is any non decreasing function. 34. 35. · BFS is an FIFO search in terms of live nodes · List of live nodes is a queue · DFS is an LIFO search in terms of live nodes · List of live nodes is a stack 29.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 27. Explain undecidable problems If the decision problem cannot be solved in polynomial time. Define a Heuristic A heuristic is a common-sense rule drawn from experience rather than from a mathematically proved assertion. 32. Define intelligent function. What are the types search strategies in branch and bound? · FIFO search · LIFO search · LC search 28. 31. x is assigned a rank using a function Öc (. problems that cannot be solved in polynomial time are called intractable problems. 30.) such that ^c (x) = f(h(x)) + Ög(x) Where h(x) is the cost of reaching x from root and f (.

Let x1. x3«. Examples are Binary search O (log n). · All NP-hard problems are not NP-complete. A literal is either a variable or its negation. 43. sorting O (n log n). 40. Differentiate between the decision and optimization problem. x2. The satiability problem is to determine if a formula is true for some assignment of truth values to the variables.81).. Let xi denotes the relation of xi. Dept. A formula in the prepositional calculus is an expression that can be constructed using literals and the operators and L or v. Differentiate between the deterministic and non deterministic algorithm. What is meant by Class NP (Non Polynomial)? Class P consists of problems whose solutions are bounded by the non polynomial.hard · NP-complete 39. What are the two classes of non polynomial time problems? · NP. Examples are Traveling salesperson problem O(n22n). Define SATISFIABILITY. Satisfiability is in P if and only if P = NP.CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 36. 41. SVSCE . Define COOK¶S theorem. What is meant by class P (Polynomial)? Class P consists of problems whose solutions are bounded by the polynomial of small degree. A clause is a formula with at least one positive literal. · All NP-complete problems are NP-hard ± TRUE. of CSE.TRUE. 42. 37. State true or false. knapsack problem O(2n/2) 38. and matrix multiplication 0(n 2.xn denotes Boolean variables.

Explain NP-complete problems A decision problem d is said to be NP-complete if 1) It belongs to class NP 2) Every problem in NP is polynomially reducible to D. · NP. What is the difference between NP.hard and NP-completeness? If all problems R NP are reducible to P. 45. SVSCE .CS2251 DESIGN AND ANALYSIS OF ALGORITHMS 2 marks questions with answers 44. If P<pQ and P is NP-Complete. Halting problem is NP-hard decision problem. Dept. Q is also NP-Complete. Explain NP-Hard problems The notion of an NP-hard problem can be defined more formally by extending the notion of polynomial reducibility to problems that are not necessary in class NP including optimization problems. 46. then P is NP-hard. · There are NP-hard problems that are not NP-complete. but it is not NP-complete. What is meant by NP hard and NP complete problem? · NP-Hard Problem: A problem L is NP-hard if any only if Satisfiability reduces to L.Complete: A problem L is NP-complete if and only if L is NP-hard and L NP. of CSE. We say P is NP-Complete if P is NP-hard and P NP. 47.