3 Antworten
0
Bottom up? Do you mean recursion?
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
0
Sky Ray here is a similar solution without the array
https://code.sololearn.com/cV3qzwj8x8Ic/?ref=app