Question

Study the Fibonacci number sequence in the following two algorithmic forms: iterative (sequential) and recursive. 1) Exa...

Study the Fibonacci number sequence in the following two algorithmic forms: iterative (sequential) and recursive.

1) Examine the theoretical measure of complexity of each.

a) Using theory compare the number of operations and time taken to compute Fibonacci numbers recursively versus that needed to compute them iteratively.

b) How many prime Fibonacci numbers are there, and how many can you find?

c) Find the smallest Fibonacci number greater than 1,000,000 and greater than 1,000,000,000

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. a.

The time complexity of the iterative code is linear, as the loop runs from 2 to n, i.e. it runs in O(n) time.

For recursive series,

for n > 1:
T(n) = T(n-1) + T(n-2) + 4 (1 comparison, 2 subtractions, 1 addition)

T(n) = T(n-1) + T(n-2) + c
     = 2T(n-1) + c
     = 2*(2T(n-2) + c) + c
     = 4T(n-2) + 3c
     = 8T(n-3) + 7c
     = 2^k * T(n - k) + (2^k - 1)*c

hence, T(n) = 2^n, i.e., exponential.

For Fibonacci series in a recursive algorithm the space required is proportional to the maximum depth of the recursion tree. hence the space complexity of Fibonacci recursive is O(N).

b) There could be infinite prime fibonacci numbers. The largest known probable Fibonacci prime is F3340367.

Add a comment
Know the answer?
Add Answer to:
Study the Fibonacci number sequence in the following two algorithmic forms: iterative (sequential) and recursive. 1) Exa...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a...

    I need help with this code. Im using C++ coding. Non Recursive (iterative) Fibonacci Write a program that uses a for loop to calculate a Fibonacci sequence (NOT RECURSIVE!!!) up to a given position, starting with position 0. This function defines a Fibonacci sequence: If the number is 0, the function returns a 0 If the number is 1, the function returns a 1 If the number is higher than 1, it returns the sum of the previous two numbers...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that...

    What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT