Professional Documents
Culture Documents
Order of Growth
Question 1 Math Functions
Determine the complexity class of the following functions using the O-notation:
Is O(2n+1 ) = O(2n )?
Is O(22n ) = O(2n )?
1
15 def f4 ( n ):
16 step = n
17 while n > 0:
18 for start in range (0 , step ):
19 for i in range ( start , n , step ):
20 body ( i )
21 n = n //2
Hint: the // operator is the floor division operator in Python. This prevents conversion of the
division result to float in Python 3.
Hint: range(start, stop, step): step defines the increment between numbers in the sequence (1
if omitted), the corresponding C code for f4 is:
1 void f4 ( int n ) {
2 for ( step = n ; n > 0; n /= 2)
3 for ( int start = 0; start < step ; start ++)
4 for ( int i = start ; i < n ; i += step )
5 body ( i );
6 }
Question 3 Algorithms
For the sorting algorithms “AKS” and “BITONIC” are the number of operations given as: