What is the complexity of the following code ?
sum = 0; for (i = 1; iWhich 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 maximumSo, 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.
Article Tags :
Recommended Articles