Question

Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently...

Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently using dynamic programming. Create a program that uses dynamic programming techniques to list the first 30 Fibonacci numbers.

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

#include <iostream>

using namespace std;

int fib[32];

int fibonacci(int n)

{

fib[0] = 0;

fib[1] = 1;

for(int i = 2; i <= n; i++)

{

fib[i] = fib[i - 1] + fib[i - 2];

}

return fib[n];

}

int main ()

{

for(int i = 0; i <= 30; i++)

cout << fibonacci(i) <<endl;

return 0;

}

=========================================================
As language was not mentioned, done in C++. Please let me know if you need in any other language.
SEE OUTPUT

Files https://ImpossibleGrowingAr main.cpp ... main.cpp #include <iostream> 2 using namespace std; 3 4 int fib[32]; 5 int fib

========================================
Thanks, let me now if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Fibonacci sequence is famous problem solved with recursion. However, this can also be done more efficiently...
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
  • Problem 7.8 (Explore: Fibonacci Identities). The Fibonacci numbers are a famous integer sequence:...

    discrete math Problem 7.8 (Explore: Fibonacci Identities). The Fibonacci numbers are a famous integer sequence: Fn) o 0, 1, 1,2,3, 5, 8, 13, 21, 34, 55, 89,... defined recursively by Fo 0, F1, and F F Fn-2 for n2 2. (a) Find the partial sums Fo+Fi +F2, Fo+ Fi +F2Fs, Fo + Fi + F2+Fs +F, FoF1+F2+ Fs+F4F (b) Compare your partial sums above with the terms of the Fibonacci sequence. Do you see any patterns? Make a conjecture for...

  • this is using MATLAB 2. Fibonacci sequence: A Fibonacci sequence is composed of elements created by...

    this is using MATLAB 2. Fibonacci sequence: A Fibonacci sequence is composed of elements created by adding the two previous elements. The simplest Fibonacci sequence starts with 1,1 and proceeds as follows: 1, 1, 2, 3, 5, 8, 13, . However, a Fibonacci sequence can be created with any two starting numbers. Create a MATLAB function called FL_fib_seq' (where F and L are your first and last initials) that creates a Fibonacci sequence. There should be three inputs. The first...

  • Problem 2: (8 pts) The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8.,.. Formal...

    Problem 2: (8 pts) The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8.,.. Formally, it can be expressed as: fib0-0 fibl-1 fibn-fibn-1+fibn-2 Write a multithreaded program that generates the Fibonacci sequence. This program should work as follows: On the command line, the user will enter the number of Fibonacci numbers that the program is to generate. The program will then create a separate thread that will generate the Fibonacci numbers, placing the sequence in...

  • fibonacci sequence in C

    The Fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, .... Formally, it can be expressed as: f ib0 = 0 f ib1 = 1 f ibn = f ibn−1 + f ibn−2 i. Write a C program using the fork() system call that that generates the Fibonacci sequence by the child process. ii. If the user input as 5 then the child process has to output up to the 5 that is output must be 0,1,1,2,3,5. iii. Parent has to print the child process id and child has to print the parent process id. iv. Parent has to finish only after the child terminates. v. Is there any process synchronization problem here? Justify your answer. vi. Modify the above program to create a zombie process. How do y ou identify the zombie process? vii. Modify the above program to create an orphan process. viii. Compare and contrast the process and threads.

  • 1. a.) The Fibonacci sequence is a famous math construct that is surprisingly often reflected in...

    1. a.) The Fibonacci sequence is a famous math construct that is surprisingly often reflected in nature. Its construction is simple, its members are simply the sum of the previous 2 numbers. So it starts like this:0, 1. 1, 2, 3, 5, 8, 13, etc. Create the truth table and Karnaugh map for a circuit that detects members of the sequence between 0 and 15 (since we have 4 input bits). (5 pts) A B C D F ABI 00...

  • Multi-threaded programming help!!! Can anyone solve this problem? It has to be written in C, runs...

    Multi-threaded programming help!!! Can anyone solve this problem? It has to be written in C, runs on Linux. his time you need to rewrite a multithreaded Pthread program that works with sleep() or pthread_join() in order to print out Fibonacci sequences properly. Create a folder name, WK6 on your class Linux machine when you work. gcc assignment3.c-Wall -Werror -pthread You are required to develop your own program using C with the following information Need to declare a function that receives...

  • 4. One interesting property of a Fibonacci sequence is that the ratio of the values of...

    4. One interesting property of a Fibonacci sequence is that the ratio of the values of adjacent members of the sequence approaches a number called "the golden ratio". Create a program that accepts the first two numbers of a Fibonacci sequence as user input and then calculates additional values in the sequence until the ratio of adjacent values converges to within 0.001 You can do this in a while loop by comparing the ratio of element k to element k...

  • Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops...

    Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops. A synthetic linear recursive procedure for this problem is provided in Code Fragment 1. A recursive function such as the one described is intuitive and easily understandable. On calling myRecursion(input), the execution first checks for the stopping condition. If the stopping condition is not met, then operations inside the recursive call are performed. This can include operations on local variables. The operations inside the function...

  • Each new term in the Fibonacci sequence is generated by adding the previous two terms. By startin...

    Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.Place your answer in R0 at the end of your program. Can you tell me what is the reason when done...

  • In the attached image you can see a problem. It would be very helpful if the problem could be bro...

    In the attached image you can see a problem. It would be very helpful if the problem could be broken down and explained, especially the symbols used and what they mean. Your help will be acknowledged 4.5 Example: Linear Least Squares Suppose we want to find the value of z that minimizes (4.21) Specialized linear algebra algorithms can solve this problem efficiently; however, an also explore how example of how these techniques work. First, we need to obtain the gradient:...

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