Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-127

Determinant by Expansion along a Row

Problem

Compute the determinant of a square matrix A by cofactor expansion along the given row index:

det(A) = sum_j (-1)^(row + j) * A[row][j] * det(minor(row, j))

Use recursive expansion of the minors.

Hint

The answer is the same for every row; only the amount of arithmetic changes.

Test cases

case 1
in: [[[1,2],[3,4]],0]
expected: -2
case 2
in: [[[1,2],[3,4]],1]
expected: -2
case 3
in: [[[2,1,3],[0,4,5],[1,0,6]],0]
expected: 41
case 4
in: [[[2,1,3],[0,4,5],[1,0,6]],2]
expected: 41
Starter codePython
def det_expand_row(A, row):
    # Your code here
    pass

4 test cases · run your code against them in the editor