Professional Documents
Culture Documents
Ind Assignement PDF
Ind Assignement PDF
Ind Assignement PDF
Show your working steps to obtain the order of growth class of the following
algorithms:
1) Algorithm 1
ALGORITHM BinRec(n)
//Input: A positive decimal integer n
//Output: The number of binary digits in
n’s binary representation
if (n == 1)
return 1
else
return BinRec(n/2) + 1
2) Algorithm 2
Algorithm Q(n)
//Input: A positive integer n
if (n == 1)
return 1
else
return Q(n − 1) + 2 ∗ n – 1
2) Please submit the assignment via Google Classroom. Late submission will be
rejected!
3) DO NOT FORGET to write your name and student id for the assignment!
A) ALGORITHM 1
T(n) = T(n/2) + 1
= T(n/4) + 1 + 1
= T(n/8) + 1 + 1 + 1
= ….
= T(1) + k
ALGORITHM 2
T(n) = T(n-1) + 2
= T(n-2) + 4
= T(n-3) + 6
….
= T(1) + n(n-1)
Therefore, T(n) = n(n-1) #[ O(n2) ]
B)
1. T(n) = T(n-1) + 5n for n > 1, T(0) = 0
….
T(n) = 5 + 10 + 15 + … + 5n
= 5(1 + 2 + 3 + … + n)
= 5n(n+1)/2
#[ 0(n2) ]
T(n) = T(n/3) + 1
= T(n/9) + 1 + 1
= T(n/27) + 1 + 1 +1
=…
#[ O(log(n)) ]