Ktunotes.In-S6-Question-Bank.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
KAITHANG Total Pages : 2 Name : −−−−−−−−−−−−−−−−−−− Roll No : −−−−−−−−−−−−−−−−−−− th 6 SEMESTER B.TECH DEGREE MODEL EXAMINATION, MARCH 2018 CS 302 DESIGN & ANALYSIS OF ALGORITHMS Duration : 3 Hrs Max. Marks : 100 PART A (Answer all Questions) 1. State Master theorem for solving recurrence relations. (3) p 2. Prove that log n grows faster than log n. (3) 3. Write the properties of Red Black Tree. (3) 4. Explain disjoint set operations (3) PART B (Answer any two Questions) 5. Build a B-Tree of degree 2 by inserting the following elements 5, 3, 21, 9, 1, 13, 2, 7, 10, 12, 4, 8 in the given order starting from an empty B-Tree. Show the B-Tree that result from the successive deletion of the keys 2, 21, 10, 3, 4 in that order starting from the constructed B-Tree (9) 6. (a) Use recursion tree to determine a good asymptotic upper bound on the recurrence (6) n T (n) = 3T ( 2 ) + n n 3 (b) Using Master method solve T (n) = 2T ( 2 )+n (3) 7. Explain the various asymptotic notations used to represent the rate of growth of running time of algo- rithms? (9) PART C (Answer all Questions) 8. Compare divide-and-conquer and dynamic programming algorithm design techniques (3) 9. What is meant by topological sorting?Where is it used? (3) 10. Write optimalitySFI principle. GEC UNIT (3) 11. Draw the tree calls of sorting an array of 10 elements using merge sort (3) PART D (Answer any two Questions) 12. Write the single source shortest path algorithm. Also analyse the performance of the algorithm (9) 13. Find the optimal parenthesization of a matrix chain product whose sequence of dimension is h5; 10; 3; 12; 5; 50; 6i (9) Downloaded from Ktunotes.in 14. Perform a DFS traversal on the following graph and mark the black edge, forward edge, and cross edge 1 SFI GEC UNIT KAITHANG PART E (Answer any four Questions) 15. Give the the algorithm forKnapsack using Greedy strategy. Also find an optimal solutio to the Knap- sack instance n=7, w=15, (P1;P2; ::::; P7) = (10, 5, 15, 7, 6, 18, 3) and (W1;W2; ::::; W7) = (2, 3, 5, 7, 1, 4,1) (10) 16. Write the Kruskal's algorithm for finding the minimum cost spanning trees? Derive the time complexity of the same algorithm (10) 17. Explain the following complexity classes with examples (10) (a) P (b) NP (c) NP-complete (d) NP-hard 18. What is backtracking? Discuss how backtracking can be used to solve the n'queens problem (10) 19. Prove that Travelling Salesman Problem is NP-complete (10) 20. Explain how 0/1 knapsack problem can be solved using backtracking (10) ********** SFI GEC UNIT Downloaded from Ktunotes.in 2 SFI GEC UNIT KAITHANG Total Pages : 15 th 6 SEMESTER B.TECH DEGREE MODEL EXAMINATION, MARCH 2018 CS 302 DESIGN & ANALYSIS OF ALGORITHMS ANSWER KEY Duration : 3 Hrs Max. Marks : 100 PART A (Answer all Questions) 1. State Master theorem for solving recurrence relations. Let a ≥ 1 and b > 1 be constants, let f(n) be a function, and let T(n) be defined on the nonnegative integers by the recurrence T(n) = aT(n/b) + f(n), where we interpret n/b to mean either bn=bc or dn=be. Then T(n) can be bounded asymptotically as follows. (a) If f(n) = O(nlogba−) for some constant > 0, then T(n)= θ(nlogba) (b) If f(n) = θ(nlogba) , then T(n)= θ(nlogba: lg n) logba+ n (c) If f(n) = Ω(n ), for some constant > 0, and if af( b ) ≤cf(n) for some constant c < 1 and all sufficiently large n, then T(n)= θ(f(n)). p 2. Prove that log n grows faster than log n p f(n)=log n, g(n) = log n f(n) log n log n 1 p 2 limn!1 g(n) = limn!1 = limn!1 1 = limn!1 log n = 1 log n log n 2 p So f(n) grows fastre than g(n). That is log n grows faster than log n 3. Write the properties of Red Black Tree. A binary search tree is a red-black tree if it satisfies the following red-black properties: (a) Every node is either red or black. (b) The root is black. (c) Every leaf (NIL) is black. (d) If a node is red, then both its children are black. (e) For each node, all paths from the node to descendant leaves contain the same number of black nodes.SFI GEC UNIT 4. Explain disjoint set operations. (a) MAKE-SET(x) :- creates a new set whose only member (and thus representative) is x. Since the sets are disjoint, then x is not already in some other set. (b) UNION(x, y) :- unites the dynamic sets that contain x and y, say Sx and Sy, into a new set that is the union of these two sets. The two sets are assumed to be disjoint prior to the operation. The representative of the resulting set is any member of Sx [ Sy. In some case specifically choose the representative of either Sx or Sy as the new representative. Since the sets in the collection to be disjoint, "destroy"Downloaded sets Sx and Sy, from by removing Ktunotes.in them from the collection . (c) FIND-SET(x) returns a pointer to the representative of the (unique) set containing x. 1 SFI GEC UNIT KAITHANG PART B (Answer any two Questions) 5. Build a B-Tree of degree 2 by inserting the following elements 5, 3, 21, 9, 1, 13, 2, 7, 10, 12, 4, 8 in the given order starting from an empty B-Tree. Show the B-Tree that result from the successive deletion of the keys 2, 21, 10, 3, 4 in that order starting from the constructed B-Tree 6. (a) Use recursion tree to determine a good asymptotic upper bound on the recurrence (6) n T (n) = 3T ( 2 ) + n Recursion tree is shown below. Level i has 3i nodes. SFI GEC UNIT th n Problem sizeat i level = ( 2i ) n Problem hits at when ( 2i ) =1 i n= 2 , i= log2 n. No.of nodes at last level = 3i = 3log2 n = nlog2 3 3 3 2 3 log2 3−1 log2 3 Take the sum of all levels = n + 2 n + ( 2 ) n + :::: + ( 2 ) n + n log 3−1 P 2 3 i log2 3 = i=0 ( 2 )Downloadedn + n from Ktunotes.in ( 3 )log2 3−1 2 log2 3 =n: 3 + n 2 −1 2 SFI GEC UNIT KAITHANG 3log2 3−1 =2n: + nlog2 3 2log2 3−1 =O(nlog2 3) n 3 (b) Using Master method solve T (n) = 8T ( 2 ) + n a = 8, b=2 , f(n)=n3 nlogb a = nlog2 8 = n3 f(n) and nlogb a grows in same rate. S0 case 3, f(n) = θ(nlogb a) n3 = θ(n3). So solution is T(n)=θ(n3: log n) 7. Explain the various asymptotic notations used to represent the rate of growth of running time of algorithms? O-Notation O(g(n)) = ff(n): there exists 2 positive constants c and n0 such that f(n) ≤ cg(n) for all n ≥ n0g. This gives asymptotic an lower bound on a function, to within a constant factor. This asymptotic upper bound provided by O-notation may or may not be asymptotically tight. A function f 2 O(g(n)) if f(n) lim = c < 1 n!1 g(n) including the case in which the limit is zero. The set of function in g(n) grows faster than the set of functions in f(n). Ω-Notation Ω(g(n)) = fSFIf(n): there exists 2 positiveGEC constants c and n0 suchUNIT that 0f(n) ≥ cg(n) for all n ≥ n0g. Downloaded from Ktunotes.in 3 SFI GEC UNIT KAITHANG This gives asymptotic an lower bound A function f 2 Ω(g(n)) if f(n) lim = c > 0 n!1 g(n) including the case in which the limit is 1. The set of function in f(n) grows faster than the set of functions in g(n). θ-Notation θ(g(n)) = ff(n): there exists positive constants c1, c2 and n0 such that c1g(n) ≤ f(n) ≤ c2g(n) for all n ≥ n0g. For all values of n to the right of n0, the value of f(n) lies at or above c1g(n) and at or below c2g(n). In other words, for all n ge n0, the function f(n) is equal to g(n) to within a constant factor. g(n) is an asymptotically tight bound for f(n). A function f 2 θ(g(n)) if f(n) lim = c n!1 g(n) The set of function in f(n) grows in same rate as g(n). o-Notation o-notation is used to denote an upper bound that is not asymptotically tight. o(g(n)) = f(n) : for any positive constant c > 0, there exists a constant n0 > 0 such that f(n)< cg(n) for all n n0. In the o-notation, the function f(n) becomes insignificant relative to g(n) as n approaches infinity. f 2 o(g(n)) if f(n) lim = 0 SFI GECn!1 g(n) UNIT !-Notation !-notation is used to denote a lower bound that is not asymptotically tight. !(g(n)) = f(n): for any positive constant c > 0, there exists a constant n0 > 0 such that f(n) > cg(n) for all n ≥ n0.