ISRO | ISRO CS 2017 | Question 19
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
Please Login to comment...