Question

Looking at the recursive formula we can design a simple program use pseudocode. Fibonacci(n): if (n...

Looking at the recursive formula we can design a simple program use pseudocode. Fibonacci(n): if (n == 0) return 0; if (n == 1) return 1; return Fibonacci (n-1) + Fibonacci(n-2).

Discuss any issues you find with your program and what reasoning there may be.

Homework Answers

Answer #1

The psedudo code is present in the code blocks below. This is an iterative approach to solve this. Similarly the formula can be directly mapped to a recursive solution as well.

getFibonacci(int n) : method  {

define F: array to store fibonacci.
// initialise starting values.
F[0] = 0, F[1] = 1;

n: int storing the max fibonacci number to get.
iterate i from 2 to n:
  F[i] = F[i-1] + F[i-2];


return F[i];
}

The above code is for a method that returns the nth fibonacci number. The only place where this could create a problem is when we have to redo the same process of calculating the fibonacci number again. To mitigate that issue, we could store fibonacci numbers to its max value and then can just refere it next time instead of calculating it.

Know the answer?
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
Similar Questions
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Use the combinations formula to prove that in general C(n, r) = C(n, n - r)....
Use the combinations formula to prove that in general C(n, r) = C(n, n - r). Use the permutations formula to evaluate for any whole number n, P(n, 0). Explain the meaning of your result. Use the combinations formula and the definition of 0! to evaluate, for any whole number n, C(n, 0). Explain the meaning of your result. Suppose you have 35 songs for a playlist consisting of only 5 songs. How many different playlists can you have?
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program....
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program. Tip: You have explicit permission to copy/paste the main method for this question, replacing instances of System.out.println with printf, where appropriate. You can get the assert function from assert.h. Try running the Java program on the CS macOS machines. You can compile and run the program following the instructions discussed in class. Assertions are disabled by default. You can enable assertions by running java...
Write a complete recursive java program to compute the heights of the tick marks on a...
Write a complete recursive java program to compute the heights of the tick marks on a ruler. Assume that the length of the ruler is a power of 2 (say L=2^n, where n >=1) , and the marks are to be placed at every point between 0 and 2^n, not including the endpoints. The endpoints 0 and 2^n will have height 0. Here are the rules for computing the heights of the ticks for a ruler of length L=2^n: 1....
Write a program that solves exercises 1.3 or 1.5. If you solve both correctly, 20 extra...
Write a program that solves exercises 1.3 or 1.5. If you solve both correctly, 20 extra points will be given. For Exercise 1.3, you can use only the following C++ function or its Java equivalent to output the results of your program: void printDigit(char c ){     if (c=='-' || c=='+' || c=='.' || c == '\n' || (c>='0' && c<='9')){         cout << c;         return;     }          cout << "Invalid characters." << endl;     return;     ...
Python recursive design question: Background: The class vote creates vote objects. A vote is either a...
Python recursive design question: Background: The class vote creates vote objects. A vote is either a blue vote, a red vote, or a purple. This information is stored in the "value" attribute. The function Poll returns a list of random votes. In the code below, some_poll is a list of 32 random votes. some_poll = Poll(32) # ----------------------------------------------------- import random # ----------------------------------------------------- # # Return a list of n random votes # # ----------------------------------------------------- def Poll(n=16): # # A random...
---------------- Overview: ---------------- This lab will consist of several independent exercises that must all use recursion...
---------------- Overview: ---------------- This lab will consist of several independent exercises that must all use recursion to solve various problems. Some problems will have fairly short solutions, but declaring and using classes/objects is still required. Some could benefit from having some kind of data structure being passed between calls. Feel free to use your LinkedList if you think it could help. Some solutions will be a mix of iteration and recursion, but all solution need to be recursive in some...
Use C++ to design a program: Your program will use three different 5-point numerical quadrature methods...
Use C++ to design a program: Your program will use three different 5-point numerical quadrature methods (Closed Newton Cotes, Gaussian Quadrature, and Lobatto Quadrature) You will employ each of these methods to solve each of the following three problems to find the area under the respective curves over the interval (-1, 1). The following is a plot of the first function f(x) = 1 - sin(1 - x)    The true area under the curve is (to 20 digits) 0.58385316345285761300.              ...
With the NPV, we are looking for a number; whereas with the IRR, we are looking...
With the NPV, we are looking for a number; whereas with the IRR, we are looking for the return. NPV can be calculated on a financial calculator, in excel, or by hand. NPV is very simply the present value (PV) of Cash inflows minus the present value (PV) of Cash outflows. Let’s look at an example. Let’s assume that you want to consider an investment of $5,000, and you are currently making 11% on that money. The payments that you...
Part A Write a 6-8 sentence summary explaining how you can use the Heap Sort algorithms...
Part A Write a 6-8 sentence summary explaining how you can use the Heap Sort algorithms to solve a real world problem. In your summary, provide a descriptive or visual explanation of your heapsort solution. Part B For this portion of the assignment you will design an algorithm to implement the solution described in part A. Your algorithm must be written in pseudocode. Note: Sample HeapSort Algorithm Pseudocode: Heapsort(A as array) BuildHeap(A) for i = n to 1 swap(A[1], A[i])...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT