retagged by
5,062 views
1 votes
1 votes
An algorithm is made up of 2 modules M1 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) * g(n)
i want the explanation how solution is option a
retagged by

2 Answers

1 votes
1 votes

Well it's O( f(n) * g(n) ) or O( max( f(n), g(n) ) )

There can be three cases possible with f(n) and g(n) -

Case A : f(n) > g(n)

In this case we take O(f(n)) the complexity of the algorithm as g(n) is a lower order term, we drop it.

Case B : f(n) < g(n)

In this case, we take O(g(n)) the complexity of the algorithm as f(n) is a lower order term, we drop it.

Case C : f(n) == g(n)

Time Complexity can be either O(g(n)) or O(f(n)) (which is equal asymptotically).

 

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

0 votes
0 votes

if f(n)=O(a(n))  and  g(n)=O(b(n)) then f(n) + g(n) = O(max (a(n) , b(n)) ) 

example-

for(j=1;j<=n; j++) { 

                          printf(“gate”);

                        }

 for(i=1,i<=n; i++) {

                       for(j=1;j<=n; j++) { 

                          printf(“gate”);

                        }

                    }                 

here 1st part take O(n) time , second part O(n^2) time

total – O(n)+O(n^2) =O(n^2)

 

if f(n)=O(a(n))  and  g(n)=O(b(n)) then f(n)*g(n) = O( a(n) * b(n) )

example – 

                   for(i=1,i<=n; i++) {

                       for(j=1;j<=n; j++) { 

                          printf(“gate”);

                        }

                    }                 

here for first loop O(n) and for second loop O(n) , so total  O(n)*O(n)=O(n^2)

 

Answer:

Related questions

0 votes
0 votes
0 answers
1
nishant_magarde asked Mar 21, 2019
484 views
Is it true?$an^{2} = O(n^{2})$ for a>0Also, what is the difference between Small-oh and Big-oh?Also, why we consider theta, omega as Big-oh sometimes, in the above probl...
0 votes
0 votes
1 answer
2
Chaitanya Kale asked Nov 10, 2022
298 views
Can we write f(2$^{n/a}$) = Θ(2$^{n}$) for any integer a >0?