-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Added matrix exponentiation approach for finding fibonacci number. #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
mahbubcseju
commented
Jul 19, 2019
- Implemented matrix exponentiation for finding nth fibonnaci.
- Complexity is about O(nlog(n)*8), here 8 is for matrix multiplication of size 2 by 2.
* Implemented the way of finding nth fibonacci. * Complexity is about O(log(n)*8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. Thanks for your contribution.
In the filename and in the code, "Fibonacci" is sometimes spelled with two n. Please fix this so that it is properly spelled in all places.
- Removed some extra spaces - Added the complexity of bruteforce algorithm - Removed unused function called zerro() - Added some docktest based on request
from timeit import timeit
print(timeit("nth_fibonacci(1000)", "from __main__ import nth_fibonacci", number=10000))
print(timeit("nth_fibonacci_test(1000)", "from __main__ import nth_fibonacci_test", number=10000)) 1.565457206 |
Yes . If the input is high like n=100000, you will get the difference. |
from timeit import timeit |
Perhaps the functions should be renamed to clarify intent:
|
24df2cd
to
d30bbc1
Compare
Changed |
- Removed some extra spaces - Added the complexity of bruteforce algorithm - Removed unused function called zerro() - Added some docktest based on request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work here!!
As a thank you for the nice work on TheAlgorithms/Python#1042... These test will run on each update to the code. You will need to log into https://travis-ci.org/mahbubcseju using your github credentials to turn on this free service. This is a simple config (but it still catches one issue on Python 3). To see a more complex config, see https://github.com/TheAlgorithms/Python/blob/master/.travis.yml
…heAlgorithms#1042) * Added matrix exponentiation approach for finding fibonacci number. * Implemented the way of finding nth fibonacci. * Complexity is about O(log(n)*8) * 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 * 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 * Tighten up main() and add comments on performance Signed-off-by: Deus-Absconditus <[email protected]>
…heAlgorithms#1042) * Added matrix exponentiation approach for finding fibonacci number. * Implemented the way of finding nth fibonacci. * Complexity is about O(log(n)*8) * 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 * 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 * Tighten up main() and add comments on performance