INSTITUTE OF TECHNOLOGY AND MARINE ENGINEERING Instructor : Kh. Jinnatul Islam Assistant Professor Department of Computer Science and Engineering [Room No: #207,SB-I. Email:
[email protected]] Subject: Design and Analysis of Algorithm Assignment No : 1
E-Type E.1.1. Define the following asymptotic notation: a)Big Oh b)Big Omega c)Theta d)Little Oh e)Little Omega. E.1.2. i)Given that f1(n)=O(g(n)) and f2(n)=O(g(n)) then prove that f1(n) may not be equal to f2(n). ii) If f1(n)=O(g1(n)) and f2(n)=O(g2(n)) then prove that f1(n)+f2(n)=O(max(g1(n),g2(n)). iii) If
f1(n)=O(g1(n)) and f2(n)=O(g2(n)) then prove that f1(n) X f2(n)=O( g1(n)xg2(n) ).
iv) If f(n) =f1(n)+f2(n) in which f1(n) & f2(n) are both non negative for all n>=0 such that Lt n->∞(f2(n)/f1(n))= L for some limit L>=0 Prove that f(n)=O(f1(n)). E.1.3. Consider the function f(n)=(n+a)m where a and m are constant. Prove that f(n)=Ө(nm). E.1.4. What do you mean by time complexity? Write an algorithm for Linear Search and find its time complexity. E.1.5. i) Prove that n!=o(nn) and n!=ω(2n) ii) Write a recursive algorithm for finding the factorial of a number and find its time complexity. E.1.6. Write an algorithm to find sum of the following series ∑ni=1 aixi. E.1.7. What do you mean by space complexity? Find the space complexity of the following two programs. a) Sum(a, n) {s=0.0; for(i=1; i<=n; i++) s=s+a[i]; return s;}
b) Recsum(a,n) { if(n<=0) return 0.0; else return Recsum(a,n-1)+a[n]; }
E.1.8. Describe RAM Model as a primitive computing model. E.1.9. Discuss Turing Machine as a primitive computing model. E.1.10. Describe the relation between Turing Machine and RAM.
M-Type M.1.1. Is 2n+1 =O(2n)? Is 22n=O(2n) ? M.1.2. Comment whether true or not: f(n)=Ω(g(n))then f(n)=o(g(n)) M.1.3. Find the time complexity of the algorithm whose running time is given by the curve(a step function) given below.
1 Running time
½ ⅓ ........... 1
2
3
1/n
4 …...……. n
H-Type H.1.1. Write an algorithm for finding the maximum element in a list and find its best, average and worst case time complexity H.1.2. Rank the following function by order of growth. i)lg∗n
ii)22^n
iii)lg n)! iv)n! v)en
vii)2n
viii)(3/2)n ix)nlg
xiii)lg(n!) xiv)ln n
lg n
vi)lg(lg∗)n
x)(n + 1)! xi) 2lg∗
xv) n3 xvi)2√2lgn xvii) lg2n
xix)√lg n xx)lnln n xxi)√2)lg
n
n
xii)4lg
n
xviii)n1/lg(n)
xxii)22^n+1 xxiii)n.2n xxiv) 2lg
[ Assumption lg n=log2n, ln n=logen, lg*n=min{i>=0:lg(i)n<=1}. lg(i)n={n if i=0, lg(lg(i-1)n) if i>0 and lg(i-1)n >0 undefined if i>0 and lg(i-1)n <0 } ]
n