Open In App

ISRO | ISRO CS 2020 | Question 21

What is the complexity of the following code ?

sum = 0;
  for (i = 1; i 

Which of the following is not a valid string ?
(A) Ο(n2)
(B) Ο(n log n)
(C) Ο(n)
(D) Ο(n log n log n)

Answer: (C)
Explanation: According to Analysis of above Algorithm:



Inner loop will run unto n time, in maximum
Outer loop will run upto logn time, in maximum 

So, total time complexity will be,

= O(n) * O(log n)
= O(n logn) 

So, Ο(n log n log n) and Ο(n2) is also correct.
But it can not be less than O(n logn), so O(n) is not correct.



Quiz of this Question

Article Tags :