mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -8,34 +8,34 @@ Space Complexity: O(n^2)
|
||||
"""
|
||||
|
||||
|
||||
def MatrixChainOrder(array):
|
||||
N = len(array)
|
||||
Matrix = [[0 for x in range(N)] for x in range(N)]
|
||||
Sol = [[0 for x in range(N)] for x in range(N)]
|
||||
def matrix_chain_order(array):
|
||||
n = len(array)
|
||||
matrix = [[0 for x in range(n)] for x in range(n)]
|
||||
sol = [[0 for x in range(n)] for x in range(n)]
|
||||
|
||||
for ChainLength in range(2, N):
|
||||
for a in range(1, N - ChainLength + 1):
|
||||
b = a + ChainLength - 1
|
||||
for chain_length in range(2, n):
|
||||
for a in range(1, n - chain_length + 1):
|
||||
b = a + chain_length - 1
|
||||
|
||||
Matrix[a][b] = sys.maxsize
|
||||
matrix[a][b] = sys.maxsize
|
||||
for c in range(a, b):
|
||||
cost = (
|
||||
Matrix[a][c] + Matrix[c + 1][b] + array[a - 1] * array[c] * array[b]
|
||||
matrix[a][c] + matrix[c + 1][b] + array[a - 1] * array[c] * array[b]
|
||||
)
|
||||
if cost < Matrix[a][b]:
|
||||
Matrix[a][b] = cost
|
||||
Sol[a][b] = c
|
||||
return Matrix, Sol
|
||||
if cost < matrix[a][b]:
|
||||
matrix[a][b] = cost
|
||||
sol[a][b] = c
|
||||
return matrix, sol
|
||||
|
||||
|
||||
# Print order of matrix with Ai as Matrix
|
||||
def PrintOptimalSolution(OptimalSolution, i, j):
|
||||
def print_optiomal_solution(optimal_solution, i, j):
|
||||
if i == j:
|
||||
print("A" + str(i), end=" ")
|
||||
else:
|
||||
print("(", end=" ")
|
||||
PrintOptimalSolution(OptimalSolution, i, OptimalSolution[i][j])
|
||||
PrintOptimalSolution(OptimalSolution, OptimalSolution[i][j] + 1, j)
|
||||
print_optiomal_solution(optimal_solution, i, optimal_solution[i][j])
|
||||
print_optiomal_solution(optimal_solution, optimal_solution[i][j] + 1, j)
|
||||
print(")", end=" ")
|
||||
|
||||
|
||||
@ -44,10 +44,10 @@ def main():
|
||||
n = len(array)
|
||||
# Size of matrix created from above array will be
|
||||
# 30*35 35*15 15*5 5*10 10*20 20*25
|
||||
Matrix, OptimalSolution = MatrixChainOrder(array)
|
||||
matrix, optimal_solution = matrix_chain_order(array)
|
||||
|
||||
print("No. of Operation required: " + str(Matrix[1][n - 1]))
|
||||
PrintOptimalSolution(OptimalSolution, 1, n - 1)
|
||||
print("No. of Operation required: " + str(matrix[1][n - 1]))
|
||||
print_optiomal_solution(optimal_solution, 1, n - 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user