


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Pallickara; Class: Algorithms and Data Structures; Subject: Computer Science; University: Colorado State University; Term: Fall 2011;
Typology: Exams
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















Consider the language that the following grammar defines: < S > = # | < W > | #< S > < W > = ab | a < W > b
Use mathematical induction to show that, 1 + 2 + 2^2 + 2^3 + 2^4 + … + 2n^ = 2n+1^ – 1 for all nonnegative integer n.
Give as good a Big O estimate as possible for each of these functions. (1) f(n ) = ( n^2 + 8)( n + 1) (2) f ( n ) = ( n log 2 n + n^2 )( n^3 +2) (3) f(n ) = ( n^2 + 1) / ( n + 1) (4) f ( n ) = 10 (5) f ( n ) = 7 * log 2 n * n
Show that x^2 + 4 x + 17 is O ( x^3 ) but that x^3 is not O ( x^2 + 4 x + 17 ). ( Hint : Use the definition of Big O estimation)
Consider the following Java method f. 1: public static void f(int[] theArray, int n){ 2: int temp; 3: for (int j = 0; j < n; ++j){ 4: int i = 0; 5: while (i <=j) { 6: if (i < j){ 7: temp = theArray[i]; 8: theArray[i] = theArray[j]; 9: theArray[j] = temp; 10: } 11: ++i; 12: } 13: } 14:} (1) How many comparisons does f perform? (We consider line 6 as the only comparison) (2) How many data movement does f perform? (We do not consider additions or initializations of integer variables as data movement.) (3) What is the Big O estimate for the total number of operation of this method f? (We consider only data movements and comparisons)
Function f satisfies the recurrence relation f ( n ) = 2 f ( n /2) +3 with f (1) = 1 (1) Find f (2), f (4), f (8), and f (16) (2) Find a closed form of f ( n ) when n = 2 k (3) Estimate the size of f using Big-‐O notation if f is an increasing function.
Design an algorithm to store and restore a binary search tree T 3 into a file. After the restoration of the tree from the file, your tree does not need to keep the same shape. Your algorithm MUST improve the computational complexity of the search operation, which you can achieve with the original shape of tree T 3. Example Tree T 3 for the problem 3 (1) Describe how to store the binary search tree T 3 in a file so that you can later restore the tree.
(2) Describe how to restore the binary search tree Tyour from the file you generated in 3-‐(1) (pseudo code, or tracing with the example tree Tyour) (3) Compare the efficiency of the search operation in your restored tree Tyour , with the one in the original tree T 3.
(1) Given the following 2-‐3 tree,T 5 -‐(1) , draw the tree that results after inserting M, A, D, X and Z into the tree. Tree T 5 (1) : for problem 5 (1)
(2) Given the following 2-‐3 tree, T 5 (2) , draw the tree that results after removing R, E, H and B from the tree Tree T 5 (2) : for problem 5 (2)