2014 June UGC NET Paper 1
October 18, 2023Programming
October 18, 2023Programming
Question 43 |
Consider the following function:
int unknown(int n) { int i, j, k = 0; for (i = n/2; i <= n; i++) for (j = 2; j <= n; j = j * 2) k = k + n/2; return k; }
Θ(n2) | |
Θ(n2 log n) | |
Θ(n3) | |
Θ(n3 logn) |
Question 43 Explanation:
Outer loop runs for (n/2) times and inner loop runs for (logn) times.
So, the total number of times loop runs is (n/2 logn).
So, the final k value will be n/2*(n/2 logn) = O(n2logn)
= (n/2+1).n/2 ∙log n
= (n2log n)
So, the total number of times loop runs is (n/2 logn).
So, the final k value will be n/2*(n/2 logn) = O(n2logn)
= (n/2+1).n/2 ∙log n
= (n2log n)
Correct Answer: B
Question 43 Explanation:
Outer loop runs for (n/2) times and inner loop runs for (logn) times.
So, the total number of times loop runs is (n/2 logn).
So, the final k value will be n/2*(n/2 logn) = O(n2logn)
= (n/2+1).n/2 ∙log n
= (n2log n)
So, the total number of times loop runs is (n/2 logn).
So, the final k value will be n/2*(n/2 logn) = O(n2logn)
= (n/2+1).n/2 ∙log n
= (n2log n)
Subscribe
Login
0 Comments