Skip to content

Commit 24df2cd

Browse files
mahbubcsejumahbubur.rahman
authored and
mahbubur.rahman
committed
Updated the matrix exponentiation approach of finding nth fibonacci.
- Removed some extra spaces - Added the complexity of bruteforce algorithm - Removed unused function called zerro() - Added some docktest based on request
1 parent b159705 commit 24df2cd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

matrix/nth_fibonacci_using_matrix_exponentiation.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
...
1111
...
1212
-> [f(n),f(n-1)] = [[1,1],[1,0]]^(n-1) * [f(1),f(0)]
13-
So we just need the n times multiplication of the matrix [1,1],[1,0]].
14-
We can decrease the n times multiplication by following the divide and conquer approach.
15-
13+
So we just need the n times multiplication of the matrix [1,1],[1,0]].
14+
We can decrease the n times multiplication by following the divide and conquer approach.
1615
"""
1716
from __future__ import print_function
1817

@@ -56,6 +55,12 @@ def nth_fibonacci(n):
5655

5756

5857
def nth_fibonacci_test(n):
58+
"""
59+
>>> nth_fibonacci_test(100)
60+
354224848179261915075L
61+
>>> nth_fibonacci_test(-100)
62+
-100
63+
"""
5964
if n <= 1:
6065
return n
6166
fib0 = 0

0 commit comments

Comments
 (0)