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
Θ(n√n)
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)