Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
Different functions that compute the Fibonacci sequence.
Project: MAT 2540
Path: Fibonacci.ipynb
Views: 120Visibility: Unlisted (only visible to those who know the link)
Image: ubuntu2004Kernel: SageMath 8.6
Fibonacci Sequence
Below is a recursive function that computes the th Fibonacci number, . The amount of code we write is small, but this cannot compute for large quickly.
In [1]:
In [2]:
0
1
1
2
3
Below is a function that computes the th Fibonacci number, , using dynamic programming. This function is faster because it trades time for space.
In [3]:
In [4]:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
Below is a function that computes the th Fibonacci number, , quickly without using much memory.
In [5]:
In [6]:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229