Implement an iterative solution that runs in on time and


Write a function called HugeInteger *fib(int n); Description: This is your Fibonacci function; this is where the magic happens.

Implement an iterative solution that runs in O(n) time and returns a pointer to a HugeInteger struct that contains F(n). Be sure to prevent memory leaks before returning from this function.

Space Consideration: When computing F(n) for large n, it's important to keep as few Fibonacci numbers in memory as necessary at any given time.

For example, in building up to F(10000), you won't want to hold Fibonacci numbers F(0) through F(9999) in memory all at once.

Find a way to have only a few Fibonacci numbers in memory at any given time over the course of a single call to fib().

Special Notes: You may assume that n is a non-negative integer.

If any dynamic memory allocation functions fail within this function, return NULL, but be careful to avoid memory leaks when you do so. Returns: A pointer to a HugeInteger representing F(n), or NULL if dynamic memory allocation fails.

There is also this to use: typedef struct HugeInteger { // a dynamically allocated array to hold the digits of a huge integer int *digits; // the number of digits in the huge integer (approx. equal to array length) int length; } HugeInteger;

Solution Preview :

Prepared by a verified Expert
Programming Languages: Implement an iterative solution that runs in on time and
Reference No:- TGS01528674

Now Priced at $10 (50% Discount)

Recommended (92%)

Rated (4.4/5)