Skip to content

Commit c21c414

Browse files
committed
refactor(matrix): Enhance code clarity by improving comments and formatting in determinant method
1 parent 16386c8 commit c21c414

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/com/thealgorithms/matrix/MatrixDeterminant.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.thealgorithms.matrix;
22

33
// Problem: Determinant of a Matrix
4+
// Description: Calculate the determinant of any square matrix using recursion.
5+
// URL: https://en.wikipedia.org/wiki/Determinant
46

57
public final class MatrixDeterminant {
68

@@ -15,16 +17,17 @@ public static double determinant(double[][] m) {
1517
throw new IllegalArgumentException("Matrix must be square");
1618
}
1719
}
20+
1821
if (n == 1) {
1922
return m[0][0];
2023
}
24+
2125
if (n == 2) {
2226
return m[0][0] * m[1][1] - m[0][1] * m[1][0];
2327
}
2428

2529
double det = 0;
2630
for (int c = 0; c < n; c++) {
27-
if (c == 0) {} // optional placeholder for clarity; main logic below
2831
det += Math.pow(-1, c) * m[0][c] * determinant(minor(m, 0, c));
2932
}
3033
return det;
@@ -34,6 +37,7 @@ private static double[][] minor(double[][] m, int row, int col) {
3437
int n = m.length;
3538
double[][] min = new double[n - 1][n - 1];
3639
int r = 0;
40+
3741
for (int i = 0; i < n; i++) {
3842
if (i == row) {
3943
continue;

0 commit comments

Comments
 (0)