Refactor Code Style (#4151)

This commit is contained in:
Saurabh Rahate
2023-04-15 13:55:54 +05:30
committed by GitHub
parent 1ce907625b
commit 1dc388653a
100 changed files with 293 additions and 319 deletions

View File

@ -8,9 +8,9 @@ package com.thealgorithms.dynamicprogramming;
// minimizes the number of scalar multiplications.
public class MatrixChainRecursiveTopDownMemoisation {
static int Memoized_Matrix_Chain(int p[]) {
static int Memoized_Matrix_Chain(int[] p) {
int n = p.length;
int m[][] = new int[n][n];
int[][] m = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
m[i][j] = Integer.MAX_VALUE;
@ -19,7 +19,7 @@ public class MatrixChainRecursiveTopDownMemoisation {
return Lookup_Chain(m, p, 1, n - 1);
}
static int Lookup_Chain(int m[][], int p[], int i, int j) {
static int Lookup_Chain(int[][] m, int[] p, int i, int j) {
if (i == j) {
m[i][j] = 0;
return m[i][j];
@ -43,7 +43,7 @@ public class MatrixChainRecursiveTopDownMemoisation {
// in this code we are taking the example of 4 matrixes whose orders are 1x2,2x3,3x4,4x5 respectively
// output should be Minimum number of multiplications is 38
public static void main(String[] args) {
int arr[] = { 1, 2, 3, 4, 5 };
int[] arr = { 1, 2, 3, 4, 5 };
System.out.println(
"Minimum number of multiplications is " + Memoized_Matrix_Chain(arr)
);