1
1
/**
2
2
* This is an implementation of finding the determinant of an nxn matrix using Laplace/cofactor
3
- * expansion. Although this method is mathematically beautiful it is computationally intensive and
3
+ * expansion. Although this method is mathematically beautiful, it is computationally intensive and
4
4
* not practical for matrices beyond the size of 7-8.
5
5
*
6
6
* <p>Time Complexity: ~O((n+2)!)
@@ -72,8 +72,7 @@ public static void main(String[] args) {
72
72
}
73
73
}
74
74
75
- // Given an n*n matrix this method finds the determinant
76
- // using Laplace/cofactor expansion.
75
+ // Given an n*n matrix, this method finds the determinant using Laplace/cofactor expansion.
77
76
// Time Complexity: ~O((n+2)!)
78
77
public static double determinant (double [][] matrix ) {
79
78
@@ -91,7 +90,7 @@ public static double determinant(double[][] matrix) {
91
90
92
91
// This method uses cofactor expansion to compute the determinant
93
92
// of a matrix. Unfortunately, this method is very slow and uses
94
- // A LOT of memory hence it is not too practical for large matrices.
93
+ // A LOT of memory, hence it is not too practical for large matrices.
95
94
private static double laplace (double [][] m ) {
96
95
97
96
final int n = m .length ;
@@ -122,8 +121,9 @@ private static double laplace(double[][] m) {
122
121
}
123
122
124
123
// Constructs a matrix one dimension smaller than the last by
125
- // excluding always the top row and some selected column. This
126
- // method uses a lot of space we called recursively multiple times.
124
+ // excluding the top row and some selected column. This
125
+ // method ends up consuming a lot of space we called recursively multiple times
126
+ // since it allocates meory for a new matrix.
127
127
private static double [][] constructMatrix (double [][] m , int skipColumn ) {
128
128
129
129
int n = m .length ;
0 commit comments