Question
Write a program that uses a recursive algorithm to calculate the determinant of a matrix. The matrix must be implemented with one or more linked
Write a program that uses a recursive algorithm to calculate the determinant of a matrix. The matrix must be implemented with one or more linked lists. No memory should be allocated for zero valued matrix elements.The program should read a matrix and calculate and print the determinant. Your matrix implementation should be that of a "sparse" matrix. Only matrix elements that are non-zero should be allocated in memory. This means you cannot implement your matrix with a 2D array.
The input is a matrix of integers.
The output is the determinant of the matrix.
If the matrix is not square, an error message is given.
Sample Input 1:
1 -2 3 -2 3 -2 3 -1 2
Sample Output 1:
-13
Sample Input 2:
1 2 3 4 1 1 1 1 4 3 2 1 1 1 1 1
Sample Output 2:
0
Sample Input 3:
1 2 3 4 5 6
Sample Output 3:
Error! Non-square matrix!
Sample Input 4:
0 0 0 0
Sample Output 4:
0
Sample Input 5:
0 1 1 0
Sample Output 5:
-1
Sample Input 6:
1 0 2 -1 0 -1 0 1 0
Sample Output 6:
-1
Sample Input 7:
5 4 -3 2 1 -1 -3 3 -4 -5 1 1 5 1 10 -2 2 -2 2 -2 1 1 1 1 1
Sample Output 7:
-640
Sample Input 8:
1 2 3 3 4 5 5 6
Sample Output 8:
Error! Non-square matrix!
Recall that the formula for the determinant of a matrix is:
det=i=0numRows1((1)i+ja[i,j]det(Minor(a[i,j])))foranyjdet=i=0numRows1((1)i+ja[i,j]det(Minor(a[i,j])))foranyj
The minor of a matrix element x is the sub-matrix formed by removing the row and column containing x.
a= 0 4 1 3
1 3 2 4
2 3 1 9
1 8 2 1
and minor a(1, 2) removes row 1 and column 2
minor(a(1,2)) = 0 4 3
2 3 9
1 8 1
Can anyone help?
det 'urnRows- ( (-1)'+, . a li, j) . det (Minor (a [i, j)))) for any jStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started