No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
O(n)forfoo()andO(2n)forbar()
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
C
O(2n)forbothfoo()andbar()
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
O(n)forbothfoo()andbar()
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution
The correct option is BO(n)forfoo()andO(2n)forbar() Therecurrencerelationforfoo(n):T(n)=T(n−1)+c;wherecisaconstant⇒T(n)=O(n)Thetimerecurrenceforbar(n);T(n)=2T(n−1)+c;cisaconstant⇒T(n)=O(2n)