Examveda

What is the time complexity of the following dynamic programming implementation used to compute the nth fibonacci term?
1. int fibo(int n)
2.	int fibo_terms[100000]  //arr to store the fibonacci numbers
3.	fibo_terms[0] = 0
4.	fibo_terms[1] = 1
5.		
6.	for i: 2 to n
7.		fibo_terms[i] = fibo_terms[i - 1] + fibo_terms[i - 2]
8.	
9.	return fibo_terms[n]

A. O(1)

B. O(n)

C. O(n2)

D. Exponential

Answer: Option B


Join The Discussion

Related Questions on Dynamic Programming in Data Structures