Question: Use a iterative for-loop to compute the Fibonacci numbers with the following formula F(0) = 0, F(1)= 1 and F(n) = F(n-1) + F(n-2_ for

  • Use a iterative for-loop to compute the Fibonacci numbers with the following formula
    • F(0) = 0, F(1)= 1 and F(n) = F(n-1) + F(n-2_ for n>1.
  • The pseudo code is provided below
  • Your program should also count the number of operations (additions) used
  • The number of operations used should be O(n) for computing F(n)

def fib_linear(n): F[0] = 0; F[1] = 1; for i = 2 to n F[i] = F[i-1] + F[i-2]; # F[2]=1, F[3]= 2, F[4]=3, . Return F[n];

# xxx you may add more function codes here

def fib_linear(n): """Compute by iteration the n_th term of Fibonacci sequence in linear Time input: integer n >=0 output: fibn : the n_th term of Fibinacci sequence count: number of the integer additions used. """ count = 0 fibn = 0 b=1

# xxx fill in the codes below return fibn, count

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!