Samle Works

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CSE 330- DESIGN AND SNALYSIS OF ALGORITHMS (1) Find the n0 and c for upper bound of f(n)=3n+2 and

f(n)=n^2+4n+2 f(n)=7n-2 f(n)=3n^3 + 20n^2 + 5 f(n)=3 log n + log log n

(2) Find the n0 and c for lower bound of 3n+3? (3) Find the n0 and c for average case of 3n+2? (4) Is 2 = (2 )? 2 = (2 )?

(4)Which function grows faster f(x)=x^2+6n or 111n-312 (5) Examine the procedure DOES_SOMETHING below and answer the following questions a. What is the function of the procedure DOES_SOMETHING? b. What is the time complexity of the procedure? c. If A[l .. r] = [24, 30, 09, 46, 15, 19, 29, 86,78], what is the output? Procedure DOES_SOMETHING(A,l,r) Input : Array A(l .. r) 1. x A[l]; i l; j r; 2. while i < j do 3. while A[i] x and i r do i i +1; 4. while A[j] > x and j l do j j -1; 5. if i< j then 6. exchange A[i] A[j]; 7. q j; 8. exchange A[l] A[q];

(6) Given an array of n numbers, suggest an O(n) expected time algorithm to determine whether there is a number in A that appears more than n / 2 times.

(7) You are given an array Arr of with M+N elements, where the first N elements in Arr are sorted and the last M elements in Arr are unsorted. 1. Evaluate the run-time complexity in term of M and N in the worst case, of fully sorting the array using insertion sort on A? 2. For each of the following cases, which sort method (or methods combination) would you use and what would be the run-time complexity in the worst case? a) M = O(1) b) M = O(logN) c) M = O(N)

You might also like