Vidyalelo
Data Structure · Q214

Dynamic Programming in Data Structures

Programming · Data Structure · question 214

Q214

What is the time complexity of the following for loop method used to compute the nth fibonacci term? 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)
Answer
C.
O(n2)
D.
Exponential

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board