# DAA TUTORIALS UNIT – I TUTORIAL - I

1. How can we modify almost any algorithm to have a good best case running time? 2. If f(n)=a0+a1n+a2n2+……………………………….+amnm is any polynomial of degree m then then prove that f(n)=O(nm) 3. If f(n)=a0+a1n+a2n2+……………………………….+amnm is any polynomial of degree m then then prove that f(n)=θ(nm) 4. For any two functions f(n) and g(n), f(n)=θ(g(n)) if f(n)=O(g(n)) and f(n)= Ω (g(n)). 5. Prove that Oθ (g(n))∩ω(g(n)) is empty set. 6. Prove that log n!= θ(n logn) 7. Prove that n!= O(nn) 8. Prove that Σni=1 log (i) is θ(n log n).

TUTORIAL - II
9. Prove that max (f(n)+g(n))= θ(f(n),g(n)) 10. For the following program give a Big-O analysis of the running time in terms of n. a. S=0; for(i=0; i<n; i++) { for(j=0; j<n; j++) { for(k=0; k<n; k++) { S++; } } } b. for(i=0; i<n; i++) { while(i==n-5){ if (i==10); i++; } }

O. . 2. Assume all the keys of T are distinct.T.R. Show that an n-element heap has height Ɩlogn˩ 15. Write pseudo code and give its complexity. Use mathematical induction to show that when n is an exact power of 2.C.O. Radix_SORT correctly sorts these numbers in θ(d(n+k)) time.N 4. the tree has at least one red node.O. What are the minimum and maximum numbers of elements in heap of height h ? 14. then for any n-key B-Tree t of height h and minimum degree t>=2. 8.T. Find the amortized cost of 8-bit binary counter using aggregate method.D.O and deleting the keys A.I. Prove that a red black tree with n internal nodes has height at most 2log(n+1). Argue that if n>1. 9.N. 17. 7. Show the red black trees that result after successively inserting the keys I.2. UNIT . 5. the solution of the recurrence T(n)= { 2 2T(n/2)+n is T(n) =n logn if n=2 if n=2k for k>1 12. Consider a red black tree formed by inserting n nodes with RB-INSERT. 3.C.II 1. 10.I. Given n digit numbers in which each digit can take up to k possible values. 6. Using accounting method find the amortized cost for Enqueue and Dequeue operation in a queue. h<=logt(N+1)/2. Write pseudo code for RIGHT-ROTATE. using shell’s increments is θ(√2).11. How can you modify quick sort for searching an element in an array.n-1 when q=0 or q=n-1 16.T. Prove that the worst case running time of shell sort. Show that q2+(n-q-1)2 achieve a maximum over q=1.----------.G. Write a recursive procedure OS-KEY-RANK(T.K) that takes as input an order statics tree T and a key K and returns the rank of K in the dynamic set represented by T. State and prove properties of binomial trees. Give steps that how to augment a data structure.U. 13.A. If n>=1.N.L.

Can we improve the algorithm given by you? 3. Multiply two matrix given below using Strassen’s method. You are given two sorted lists of size m and n.UNIT . Prove that if we order the characters in an alphabet so that their frequencies are monotonically decreasing. Consider the following graph. What is the cost of its minimum spanning tree? b. Suppose Kruskal’s algorithm is run on this graph.III TUTORIAL 1. In what order are the edges added to the MST. . Give an O(logn+logn) time algorithm for computing the kth smallest element in the union of two lists. then there exists an optimal code whose code word length are monotonically increasing? 5. How many minimum Spanning trees does it have? c. 2 6 9 10 3 2 4 6 8 10 11 9 11 9 10 6 8 21 4 12 4. 6 A B 5 C 6 D 1 2 2 5 4 5 7 E F G H 1 3 3 a. Design an algorithm that multiply two n-bit integers. in O(n2) time using divide and conquer technique. 2.

2 S a 4 C 1 d 2 f -2 3 b -3 5 2 e 1 . 1 2 3 4 8 6 6 2 1 4 5 1 1 a. Show how to find the maximum spanning tree of a graph that is. 9. starting node A. always use alphabetic ordering (eg.E) be an undirected Graph. Show how the disjoint sets data structure looks at every intermediate stage. whenever there is a choice of nodes.6. Suppose Dijkstra’s algorithm is run on the following graph. 7. Start node A) Draw a table showing the intermediate values of the cost array. Run Kruskal algorithm on the same graph. the spanning tree of largest total weight. show final shortest path tree. 8. Run Prim’s algorithm. 1 A B 2 C 1 D 4 8 6 6 2 1 4 E F G H 5 1 1 10. Find the shortest path using Bellman Ford algorithm from 3 to 1 of the following graph. b. Prove that if all its edge weights are distinct. then it has a unique minimum spanning tree. Let G=(V.

Find optimal solution to the 0/1 Knapsack instant n=7. 5.11. 5. 7. 7. 18. 4. 1. Find Shortest path from vertex 1 to 6 using graph shown below. (P1. W2…………… W7)=(2. 3. W=15. 1) 2. 21 1 2 6 5 4 10 2 -3 6 5 3 a. 15.Using Dijkstra Algorithm b. Write an algorithm (Floyd Warshal) and explain it using following graph. 6.Using Belman Ford Algorithm UNIT – IV TUTORIAL – IV 1. P2………………… P7)=(10. You are also required to find its complexity . 3) and (W1.

Analyze the complexity of the algorithm. Apply it on Matrix –Chain multiplication. Let W={5. Explain Dynamic programming. Analyze the complexity of the algorithm. Find Matrix Multiplication for following two matrices 3 8 6 9 3 2 9 4 3 6 4 8 8 6 9 4 10 7 2 5 3 2 4 3 G J 6.2 1 2 3 4 6 6 1 3 8 3 4 6 7 4 2 5 3. Explain the algorithm using following graph where n=3. What do you mean by graph coloring. 7. 10. Give a dynamic programming solution for the subset sum problem. 7. Do this using Sum-of –subset algorithm. Run N-Queen algorithm for n=5. Tabulate the no of solutions. 20} and M=35. Draw the portion of state space tree that is generated. 5. 15. A B C D K I H F E L 4. Find all possible subsets of w that sum to m. 12. Find the Hamilton Circuit in the following graph using back tracking. 8. 18. .

0 5 6 8 10 0 13 8 15 9 0 9 20 10 12 0 UNIT – IV . 7 2 2 9 8 3 6 4 6 2 4 3 4 2 8 2 9 1 10.A B E C D 9. Distinguish Divide and Conquer and Dynamic programming approach. Find solution of TSP defined by the edge length Matrix X using Dynamic programming method approach. Explain assembly line scheduling using following graph.

TUTORIAL 1. . Give a recurrence for the running time. and solve the recurrence. Describe the generalization of the FFT procedure to the case in which n is a power of 3. Working modulo q=11. Explain Boyer’s Moore string matching algorithm using text T=010010101101 and pattern P=01011. Suppose that all characters in the pattern P are different. Prove that the Traveling Salesman problem is NP complete. 10. 9. Draw a state transition diagram for a string matching automation for pattern Ababbabbababbababbabb over the alphabets Σ={a. Show how to accelerate NAÏVE-STRING-MATCHER to run in time O(n) on n character text T.looking for a pattern P=26 8. 2. Explain also KMP algorithm. 6. Compute the prefix function π for the pattern ababbabbabbababbabb when the alphabet is Σ={a.b} 5. 7. Construct the string matching automation for the pattern P=aabab and illustrate its operation on the text string T=aaababaabaababaab 4. State and prove overlapping –Suffix lemma. how many spurious hits does the Rabin Karp matcher encounter in the text T=3141592653589793 when . (Hint-consider the inverse of DFT 3. of the computation. Show how to implement FFT algorithm with the bit reversal permutation occurring at the end.b}. rather than at the beginning.