int fibo(int n)
if n == 0
return 0
else
prevFib = 0
curFib = 1
for i : 1 to n-1
nextFib = prevFib + curFib
prevFib = curFib
curFib = nextFib
return curFib
a) O(1)
b) O(n)
c) O(n2)
d) Exponential
What is the time complexity of the following for loop method used to compute the nth fibonacci term?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
What is the time complexity of the following for loop method used to compute the nth fibonacci term?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!