![]() |
VOOZH | about |
The determinant of a Matrix is defined as a special number that is defined only for square matrices (matrices that have the same number of rows and columns). A determinant is used in many places in calculus and other matrices related to algebra, it actually represents the matrix in terms of a real number which can be used in solving a system of a linear equation and finding the inverse of a matrix.
The value of the determinant of a matrix can be calculated by the following procedure:
- For each element of the first row or first column get the cofactor of those elements.
- Then multiply the element with the determinant of the corresponding cofactor.
- Finally, add them with alternate signs. As a base case, the value of the determinant of a 1*1 matrix is the single value itself.
The cofactor of an element is a matrix that we can get by removing the row and column of that element from that matrix.
30
Time Complexity: O(n3)
Space Complexity: O(n2), Auxiliary space used for storing cofactors.
Note: In the above recursive approach when the size of the matrix is large it consumes more stack size.
We calculates the determinant of an N x N matrix using Gaussian elimination and a series of transformations that reduce the matrix to upper triangular form.
- Converting the given matrix into an upper triangular matrix using determinant properties
- The determinant of the upper triangular matrix is the product of all diagonal elements.
- Iterating every diagonal element and making all the elements down the diagonal as zero using determinant properties
- If the diagonal element is zero then search for the next non-zero element in the same column.
There exist two cases:
30
Time complexity: O(n3)
Auxiliary Space: O(n), Space used for storing row.
There is a built-in function or method in linalg module of NumPy package in python. It can be called numpy.linalg.det(mat) which returns the determinant value of the matrix mat passed in the argument.