How to use bottom up method to find the nth number in the Fibonacci sequence. I need the code in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use bottom up method to find the nth number in the Fibonacci sequence. I need the code in python

Dynamic programming python

1st Feb 2020, 10:05 PM
Sky
Sky - avatar
3 Answers
0
Bottom up? Do you mean recursion?
7th Jan 2021, 8:40 AM
Ray
0
Sky I came across your question and noticed it remains unanswered. Here is the Fibonacci Sequence nth digit solution without using recursion. The problem with recursion is when you're looking for a digit that is far down in the sequence. For example the 20,000th digit. Since recursion uses the call stack you can get into stack overflow problems, not to mention it's sloooow. If you consider a simple problem such as finding the 5th digit. The recursive function must first figure out fib(4) and fib(4) must have the answer to fib(3) and fib(3) must have the answer to fib(2) and finally fib(1). the result is that each are called multiple times starting with fib(3). The inefficiency of this is not to impactful for the 5th digit, but at 1,000th, 10,000th or 100,000th it's another thing. Ray https://code.sololearn.com/c9S9WgN4aQ0Z/?ref=app
30th Aug 2021, 11:39 PM
Paul K Sadler
Paul K Sadler - avatar
0
Sky Ray here is a similar solution without the array https://code.sololearn.com/cV3qzwj8x8Ic/?ref=app
31st Aug 2021, 3:31 AM
Paul K Sadler
Paul K Sadler - avatar