wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C function:
int fun (int n)
{ int i, j;
for (i = 1; i <= n; i++)
{ for (j = 1; j < n; j + = i)
{ printf{"%d % d", i, j);}}}
Time complexity of fun in terms of Θ notation is

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

The correct option is C Θ(n log n)
First loop will execute 'n' times and the inner loop will execute Θ (log n) times.
Hence the complexity will be Θ(n log n)

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Change of Variables
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon