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

Cosider the following code
foo(int n)
{
int x = 0;
if (n == 1) return;
for (i=1; i<=n; ++i)
x + = foo (n-1);
return (x);
}

The worst case complexity of time is

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

The correct option is D O(n!)
T(n)=nT(n1)

Which evaluates to O(n!)

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