Vous êtes sur la page 1sur 9

1. What is meant by time complexity and space complexity of an algorithm?

Time Complexity : It is amount of taken by an algorithm to execute its operation Space Complexity: It is amount of memory space that is occupied by any algorithm to execute its operation. 2. Define Big Omega Notation A Function T(n) is said to be in (g(n)), denoted t(n) (g(n)), if t(n) is bounded below by some positive constant multiple of g(n) for all large n. 3. Write the general divide and conquer recurrence relation. Running time T(n) = a T(n/b) + f(n). 4. What do you mean by best-first branch and bound? All the children of the most promising node are generated and compared by their lower bounds. This strategy is called the best-first branch and bound. 5. What is the time efficiency class of the greedy algorithm for the knapsack problem? Justify your answer The time efficiency class of the greedy algorithm for the knapsack problem is O(n). As the considerations are given to each n objects by checking its weight with the maximum limit of the knapsack, it requires the O(n) to solve this problem. 6. What is called All-Pair shortest path problem. To find the distances (the length of the shortest paths)from each vertex to all other vertices. It is convenient to record the lengths of shortest paths in an n-by-n matrix D called the distance matrix. 7. What do you mean by state space tree? Its root represents an initial state before the search for a solution begins. The nodes of the first level in the tree represent the choice made for the first component of a solution. The nodes of the second level represents the choice for the second component. 8. Define N Queen problem. It is to place n queens on an n-by-n chess board so that no two queens attack each other by being in the same row or in the same column or on the same diagonal. 9. What is called as deterministic algorithm? A deterministic algorithm will give the exact answer. 10. Explain Exhaustive search. Searching an element in all possibilities. PART - B MARKS) 11. a) i.) ( 5 X 16 = 80

What are the important problem types? Explain them. (8)

i. Sorting ii. Searching iii. String Processing iv. Graph Problems v. Combinatorial Problems. vi. Geometric Problems vii. Numeric Problems & Explanation for each technique. ii) 1) Find Prove that100n + 5 O ( n2 ) (4) 100n + 5 <=100n + n(For all n>=5)= 101n<= n2 100n + 5 <=100n +5n(For all n>=1)= 105n to complete the proof with c=105 and n0=1 2) Compare orders of growth of n! and 2n (4) lim n!/ 2n = lim 2n nn /2nen = n-> n-> Big Omega Notation , 2n grows very fast n! n! (2n) (OR)

b) i) With Illustrations, explain Recursive algorithm analysis. (8) Recursive Algorithm : An algorithm that makes use of a recursive function which calls itself again and again. Recursive algorithm: Algorithm fact(n) If (n==0) Return(1); Else Return(n*fact(n-1)); Time Complexity = (n) ii) Discuss the various asymptotic notations. (8) O-notation A function f(n) is said to be in the O(g(n)), denoted by f(n) = O(g(n)), if there exist some positive constant c and some nonnegative integer n0 such that f(n) <= cg(n) for all n >= n0 -notation A function f(n) is said to be in the (g(n)), denoted by f(n) = (g(n)), if there exist some positive constant c and some nonnegative

integer n0 such that f(n) >= cg(n) for all n >= n0 -notation A function f(n) is said to be in the (g(n)), denoted by f(n) = (g(n)), if there exist some positive constants c1 and c2 and some nonnegative integer n0 such that c2g(n) <= f(n) <= c1g(n) for all n >= n0 12.a) i) Give the Quick sort algorithm. Explain its working with an example. (8) The most well known algorithm design strategy: Divide instance of problem into two or more smaller instances Solve smaller instances recursively Obtain solution to original (larger) instance by combining these solutions Algorithm: ALGORITHM Quicksort(A[l..r]) If (l<r) S Partition(A[l..r]) Quicksort(A[l .. s-1]) Quicksort(A[s+1 .. r]) Algorithm Partition partitions a sub array by using its first element as a pivot. Best case efficiency: ( n log n) Worst case efficiency : (n2) Average case efficiency : ( n log n) ii) Form minimum cost spanning tree using Kruskals Algorithm. (8)

Start with empty forest of trees grow MST one edge at a time intermediate stages usually have forest of trees (not connected)

at each stage add minimum weight edge among those not yet used that does not create a cycle edges are initially sorted by increasing weight at each stage the edge may: expand an existing tree combine two existing trees into a single tree create a new tree need efficient way of detecting/avoiding cycles algorithm stops when all vertices are included Ans:1 -6, 2-3,3-4, 4-5,2-7,5-6 10+16+12+22+14+25 Draw the respective spanning tree (OR) b) i) Give Recurrence Strassens matrix multiplication using Divide- and (8) conquer algorithm and its computing time.

Strassen observed [1969] that the product of two matrices can be computed as follows:

C00 C01

A00 A01 =

B00 B01 * B10 B11

C10 C11

A10 A11

M1 + M4 - M5 + M7 M5 = M2 + M4 M3 - M2 + M6

M3 +

M1 +

M1 = (A00 + A11) * (B00 + B11)

M2 = (A10 + A11) * B00

M3 = A00 * (B01 - B11)

M4 = A11 * (B10 - B00)

M5 = (A00 + A01) * B11

M6 = (A10 - A00) * (B00 + B01)

M7 = (A01 - A11) * (B10 + B11)

b)ii) Give the Dijkstras Algorithm and explain its working with an example. (8) Greedy Optimization problems solved through a sequence of choices that are: Feasible, locally optimal & irrevocable Not all optimization problems can be approached in this manner! Single Source Shotest Paths Problem: Given a weighted graph G, find the shortest paths from a source vertex s to each of the other vertices. Dijkstras algorithm: Similar to Prims MST algorithm, with the following difference: Start with tree consisting of one vertex grow tree one vertex/edge at a time to produce MST Construct a series of expanding subtrees T1, T2,

Keep track of shortest path from source to each of the vertices in Ti at each stage construct Ti+1 from Ti: add minimum weight edge connecting a vertex in tree (Ti) to one not yet in tree choose from fringe edges (this is the greedy step!)

algorithm stops when all vertices are included Doesnt work with negative weights Applicable to both undirected and directed graphs 13.a) i) Explain in detail about Warshalls algorithm. (8)

Computes the transitive closure of a relation (Alternatively: all paths in a directed graph) Example of transitive closure: Main idea: a path exists between two vertices i, j, iff there is an edge from i to j; or there is a path from i to j going through vertex 1; or there is a path from i to j going through vertex 1 and/or 2; or there is a path from i to j going through vertex 1, 2, and/or 3; or ... there is a path from i to j going through any of the other vertices In the kth stage determine if a path exists between two vertices i, j using just vertices among 1,,k R(k-1)[i,j] (path using just 1 ,,k-1) R(k)[i,j] = or (R(k-1)[i,k] and R(k-1)[k,j]) (path from i to k and from k to i using just 1 ,,k-1) ii) Apply warshalls algorithm to find the transitive closure of the digraph defined by the following adjacency matrix. (8) 1 0 1 1 0 0 0 0 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 1 0

Ans: 10111 10111 10111 10111 10111 (OR) b) Find the OBST for the following: Key Probability a .4 B .05 c .15 d .05 e .1 f .25 (16)

Apply Dynamic programming algorithm draw two tables and find out the answer. 14.a Explain in detail about subset-sum problem. Given a set S = { 1,3,4,5 } and X = 8. Find subset sum using Backtracking problem. (16) Ans: x2 = 1 and x4 = 1 3+5 = 8 therefore 3 and 5 are included (OR) b) Consider the following weighted Graph. Apply Branch and Bound technique to solve the traveling Sales Person problem. (16) 4 a 6 7 8 5 3 e d 4 10 b

2 c

1. Draw the state space Tree 2. Find the lower bound for each node and find the optimal tour a-b +b-d+d-e+e-c+c-a ==4+8+4+3+2 = 21 15.a) Discuss the Approximation algorithm for Traveling Salesman problem. Explain with an Example. (16) i. Nearest neighbor algorithm ii. Twice-around-the-tree-algorithm (OR) b) Compare class P, class NP, NP-Hard and NP- Complete problems. (16) P: the class of decision problems that are solvable in O(p(n)), where p(n) is a polynomial on n NP: the class of decision problems that are solvable in polynomial time on a nondeterministic machine (A determinstic computer is what we know) A nondeterministic computer is one that can guess the right answer or solution Thus NP can also be thought of as the class of problems whose solutions can be verified in polynomial time; or that can be solved in polynomial time on a machine that can pursue infinitely many paths of the computation in parallel Note that NP stands for Nondeterministic Polynomial-time Exhibited nondeterministic poly-time algorithm for CNF-satisfiability CNF-sat is in NP Similar algorithms can be found for TPS, HC, Partition, etc proving that these problems are also in NP All the problems in P can also be solved in this manner (but no guessing is necessary), so we have: P NP A decision problem D is NP-complete iff 1. D NP 2. every problem in NP is polynomial-time reducible to D A NP Complete problem is one which belongs to the NP class and which has a surprising property. Every problem in NP class can be reduced to this problem in polynomial time on a deterministic machine A formal definition for the same is given below A decision problem D is said to NP Complete if 1. If it belongs to NP class 2. Every problem in the NP class is polynomially reducible to D (8) (8)

A problem P is said to be a NP Hard problem if any problem (not necessarily in NP) is polynomially reducible to P _ NP Hard problems are basically the optimization versions of the problems in NP Complete class The NP Hard problems are not mere yes/no problems. They are problems where in we need to find the optimal solution

Vous aimerez peut-être aussi