Pham Quỳnh Anh
New member
What is the time complexity of the following for loop method used to compute the nth fibonacci term?
A. O(1)
B. O
C. O(n$^{2}$)
D. Exponential
Code:
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
B. O
C. O(n$^{2}$)
D. Exponential