Skip to content
Related Articles
Open in App
Not now

Related Articles

ISRO | ISRO CS 2017 | Question 19

Improve Article
Save Article
Like Article
  • Last Updated : 15 Mar, 2018
Improve Article
Save Article
Like Article

Consider the program

void function(int n) {
int i, j, count=0;
for (i=n/2; i <= n; i++)
for (j = 1; j <= n; j = j*2)
count++;}

The complexity of the program is
(A) O(log n)
(B) O(n2)
(C) O(n2 log n)
(D) O(n log n)


Answer: (D)

Explanation: The outer loop runs n/2 times
The inner loop runs logn times
Therefore the total time complexity of the program is O(nlogn) which is option (D)

Quiz of this Question

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!