CameraIcon
CameraIcon
SearchIcon
MyQuestionIcon
MyQuestionIcon
95
You visited us 95 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C function.
int fun1 (int n)
{
int i, j, k, p, q = 0;
for (i = 1; i < n; + + i)
{
p = 0;
for (i = n; j > 1; j = j/2)
++p;
for (k = l; k < p; k = k*2)
+ + q:
} return q;
}
Which one of the following most closely approximates the return value of the function fun1?

A
n (log n)2
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
n log (log n)
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
n log n
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
n3
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is B n log (log n)
int fun1(int n)
{
int i, j, k, p, q = 20
for (i = 1; i < n; ++ i)
{ P = 0;
for (j = n; j < 1; j = j/2) log n times for each i Total = n × log n ++p;
for (k = 1; k < p; k = k × 2) log log n times for each i Total n log n
++q;
}
return q; Return value = O(n log log n)
}
Time complexity of above program = O(n log n)
Return value q = O(n log log n)

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Visualising the Terms
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon