2014 June UGC NET Paper 1
October 18, 2023
Programming
October 18, 2023
2014 June UGC NET Paper 1
October 18, 2023
Programming
October 18, 2023

Programming

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;
 }
A
Θ(n2)
B
Θ(n2 log n)
C
Θ(n3)
D
Θ(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)
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)
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!