![]() |
Python
1.0
|
Fibonacci sequence. More...
Functions | |
def | fiboDumb (n) |
This is a naive recursive version. More... | |
def | fibo (n, p=False) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls. More... | |
def | fib (n) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls. More... | |
def | fib2 (n, p0, p1) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls. More... | |
def | main () |
Fibonacci sequence.
The Fibonacci Sequence is the series of numbers: \(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...\)
where the next number is found by adding up the two numbers before it.
def _01a_fibo_rec.fib | ( | n | ) |
def _01a_fibo_rec.fib2 | ( | n, | |
p0, | |||
p1 | |||
) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls.
n | index of a Fibonacci number. |
p0 | a Fibonacci number. |
p1 | the Fibonacci number following p0. |
Referenced by fib().
def _01a_fibo_rec.fibo | ( | n, | |
p = False |
|||
) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls.
n | index of a Fibonacci number. |
p | turns printing on or off. |
Referenced by main().
def _01a_fibo_rec.fiboDumb | ( | n | ) |
This is a naive recursive version.
The number of calls is \(O((\frac {(1+\sqrt{5})}{2})^n) = O(1.618^n)\), that is, for n = 20 there are 21891 calls.
n | index of a Fibonacci number. |
Referenced by main().
def _01a_fibo_rec.main | ( | ) |
References fib(), fibo(), fiboDumb(), and _01d_dec2bin.input.