Tut - 1 Asymptotic Complexity
Tut - 1 Asymptotic Complexity
Specific topics:
Asymptotic upper and lower bounds of algorithms, properties of asymptotic growth rates, some common
running times, and ordering of functions with respect to asymptotic behavior.
1. Order the following functions according to their order of growth (from the lowest to the highest).
√
(a) n n , 2n , n10 2n/2 , ni=1 (i + 1).
P
3. Suppose that the functions f and g is such that f (n) is O(g(n)). Prove or disprove the following:
(a) log2 f (n) is O(log2 g(n))
(b) 2f (n) is O(2g(n) )
(c) f (n)2 is O(g(n)2 )
4. The Fibonacci sequence is a sequence of numbers recursively defined as follows:
F0 = 0, F1 = 1, Fn+2 = Fn + Fn+1
For example, the first few terms of the Fibonacci sequence are
Prove the following for the recursive algorithm above to compute the nth Fibonacci number.
(a) T (Fn ) = O(2n )
(b) T (Fn ) = Ω(2n/2 ).
5. Consider the following procedure, which takes as input an array A:
1
Algorithm 1: The recursive function printStuff
Function printStuff(A):
n ← length of A
if n ≤ 4 then
return
for i = 0, . . . , n − 1 do
print A[i ]
printStuff (A[:n/4]) # recurse on first n/4 elements of A
printStuff (A[3n/4:]) # recurse on last n/4 elements of A
return