Consider the program
void function(int n) { int i, j, count=0; for (i=n/2; iThe 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
Article Tags :
Recommended Articles