mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 18:49:26 +08:00
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88 * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Implementation of finding nth fibonacci number using matrix exponentiation.
|
||||
Time Complexity is about O(log(n)*8), where 8 is the complexity of matrix multiplication of size 2 by 2.
|
||||
Time Complexity is about O(log(n)*8), where 8 is the complexity of matrix
|
||||
multiplication of size 2 by 2.
|
||||
And on the other hand complexity of bruteforce solution is O(n).
|
||||
As we know
|
||||
f[n] = f[n-1] + f[n-1]
|
||||
@ -70,7 +71,10 @@ def nth_fibonacci_bruteforce(n):
|
||||
|
||||
|
||||
def main():
|
||||
fmt = "{} fibonacci number using matrix exponentiation is {} and using bruteforce is {}\n"
|
||||
fmt = (
|
||||
"{} fibonacci number using matrix exponentiation is {} and using bruteforce "
|
||||
"is {}\n"
|
||||
)
|
||||
for ordinal in "0th 1st 2nd 3rd 10th 100th 1000th".split():
|
||||
n = int("".join(c for c in ordinal if c in "0123456789")) # 1000th --> 1000
|
||||
print(fmt.format(ordinal, nth_fibonacci_matrix(n), nth_fibonacci_bruteforce(n)))
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""
|
||||
In this problem, we want to rotate the matrix elements by 90, 180, 270 (counterclockwise)
|
||||
In this problem, we want to rotate the matrix elements by 90, 180, 270
|
||||
(counterclockwise)
|
||||
Discussion in stackoverflow:
|
||||
https://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-array
|
||||
"""
|
||||
|
@ -207,8 +207,10 @@ class Matrix:
|
||||
"""
|
||||
<method Matrix.ShermanMorrison>
|
||||
Apply Sherman-Morrison formula in O(n^2).
|
||||
To learn this formula, please look this: https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula
|
||||
This method returns (A + uv^T)^(-1) where A^(-1) is self. Returns None if it's impossible to calculate.
|
||||
To learn this formula, please look this:
|
||||
https://en.wikipedia.org/wiki/Sherman%E2%80%93Morrison_formula
|
||||
This method returns (A + uv^T)^(-1) where A^(-1) is self. Returns None if it's
|
||||
impossible to calculate.
|
||||
Warning: This method doesn't check if self is invertible.
|
||||
Make sure self is invertible before execute this method.
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
"""
|
||||
Testing here assumes that numpy and linalg is ALWAYS correct!!!!
|
||||
|
||||
If running from PyCharm you can place the following line in "Additional Arguments" for the pytest run configuration
|
||||
If running from PyCharm you can place the following line in "Additional Arguments" for
|
||||
the pytest run configuration
|
||||
-vv -m mat_ops -p no:cacheprovider
|
||||
"""
|
||||
|
||||
|
Reference in New Issue
Block a user