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

Consider the following functions, foo() and bar():The time complexity of the functions foo()and bar() isint foo(int n){ if(n<=1) return 2n; return 8*foo(n−1);}int bar(int n){ if (n<=1)return 3n; return 3∗bar(n−1) +2*bar(n−1);}

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

The correct option is B O(n) for foo() and O(2n) for bar()
The recurrence relation for foo(n): T(n) = T(n1)+c; where c is a constant T(n) = O(n)The time recurrence for bar(n); T(n) = 2T(n1)+c; c is a constant T(n) = O(2n)

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