279 views
0 votes
0 votes
  The function for finding the fibonacci series is given as follows :

Image not present

The number of additions taken in evaluating fib(5) is.

Your Answer:

4

Correct Answer: 7    Status: incorrect

1 Answer

0 votes
0 votes
fib (5)  = fib(4) +  fib(3)

fib(4) = fib(3) + fib(2)

fib(3) = fib(2) + fib(1)   

fib(2) = fib(1) + fib(0)    

 

Now, for last simplication, 1 additions. Then we store fib(2) in fibonacci array.

For fib(3), 1 addition. Again we store fib(3).

 

And so on. This is perfect example of dynamic programming.

So, answer = 4

Related questions

0 votes
0 votes
0 answers
1
0 votes
0 votes
1 answer
4