You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-7
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,8 @@ Fibonacci Algorithms
4
4
This repository contains example programs of different algorithms used to calculate fibonacci numbers.
5
5
6
6
7
-
Naive
8
-
-----
7
+
Naive (`fib_naive`)
8
+
---------------------
9
9
10
10
This algorithm is based directly on the mathematical definition. It has a running time of `Θ(ϕ^n)` where n is the term of the sequence. Exponential, not good.
11
11
@@ -15,8 +15,8 @@ This algorithm is based directly on the mathematical definition. It has a runnin
15
15
return fib (n - 1) + fib (n - 2);
16
16
17
17
18
-
Bottom-up
19
-
---------
18
+
Bottom-up (`fib_bottomup`)
19
+
----------------------------
20
20
21
21
This algorithm is called the bottom-up algorithm because it iterates from 0 to n adding as it goes along. It has a running time of `Θ(n)`. It's okay but we can do better.
22
22
@@ -33,14 +33,26 @@ This algorithm is called the bottom-up algorithm because it iterates from 0 to n
33
33
return b;
34
34
35
35
36
-
Matrix multiplication
37
-
---------------------
36
+
Matrix multiplication (`fib_matrix`)
37
+
------------------------------------
38
38
39
-
This uses exponentiation by squaring to compute the nth power of a 2x2 matrix. It has a running time of `Θ(log_2 n)`. It takes advantage of the theorem:
39
+
This uses exponentiation by squaring to compute the nth power of a 2x2 matrix. It has a running time of `Θ(log n)`. It takes advantage of the theorem:
This is practically the same as above, but with fewer variables and simpler code. It has the same running time of `Θ(log n)`.
53
+
54
+
55
+
GMP Built-in (`fib_gmpbuiltin`)
56
+
-------------------------------
57
+
58
+
The GMP library comes with its own routine for finding the nth fibonacci sequence. However it only accepts an `unsigned long int` argument instead of its `mpz_t` integer type.
0 commit comments