Data Structures

1: An algorithm is made up of 2 modules Ml and M2. If order of M1 is f(n) and M2 is g(n) then the order of the algorithm is  
A.

max (f (n) ,g (n))

B.

min (f (n) ,g (n) )

C.

f (n) + g (n)

D.

f (n) x g (n )

 

Answer : A

Explanation :

 

By definition of order, there exists constants c1, ec2, n1, n2 such that
T (n)   ≤ c1 x f (n) , for all n  ≥ n1.
T (n)   ≤ c2 x f (n) , for all n  ≥ n2.
N = max (n1, n2) andC = max (c1, c2). So,
T (n)  ≤ C x f(n) for all n  ≥ N
T (n)  ≤  C x g (n) for all n  ≥  N
T(n) ≤ C/2 x (f(n)+g(n))
Without loss of generality, let max ( f (n), g (n)) =f(n) .
So, T (n)   ≤ C / 2 (f(n) + f (n) ) ≤ C x f(n) .
So, order is  f(n) , which is max (f(n), g (n) ) , by our assumption.

 

Write your comments here:


Report Error
 

Option: A

Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here.