TExcelTAD
Home › Linear Algebra & Matrix Theory › Minors and Cofactors

Minors and Cofactors

Cofactor expansion defines the determinant of any n×nn \times n matrix in terms of determinants of (n−1)×(n−1)(n-1) \times (n-1) matrices. It is the natural recursive definition, it lets you exploit rows full of zeros, and it is hopelessly slow for large matrices, which is a lesson in itself.

Minors and cofactors

For an n×nn \times n matrix AA:

  • the minor MijM_{ij} is the determinant of the (n−1)×(n−1)(n-1) \times (n-1) matrix obtained by deleting row ii and column jj;
  • the cofactor is Cij=(−1)i+j⋅MijC_{ij} = (-1)^{i+j} \cdot M_{ij}.

The sign (−1)i+j(-1)^{i+j} follows a checkerboard pattern starting with ++ in the top-left corner:

[+−+−−+−++−+−−+−+]\begin{bmatrix} + & - & + & - \\ - & + & - & + \\ + & - & + & - \\ - & + & - & + \end{bmatrix}

Example with A=[2−1304152−2]A = \begin{bmatrix} 2 & -1 & 3 \\ 0 & 4 & 1 \\ 5 & 2 & -2 \end{bmatrix}: deleting row 1 and column 2 leaves [015−2]\begin{bmatrix} 0 & 1 \\ 5 & -2 \end{bmatrix}, so M12=0⋅(−2)−1⋅5=−5M_{12} = 0 \cdot (-2) - 1 \cdot 5 = -5 and C12=(−1)3⋅(−5)=5C_{12} = (-1)^3 \cdot (-5) = 5.

Cofactor (Laplace) expansion

Theorem. For any fixed row ii,

det⁡A=ai1Ci1+ai2Ci2+⋯+ainCin(expansion along row i)\det A = a_{i1}C_{i1} + a_{i2}C_{i2} + \cdots + a_{in}C_{in} \qquad (\text{expansion along row } i)

and for any fixed column jj,

det⁡A=a1jC1j+a2jC2j+⋯+anjCnj(expansion along column j)\det A = a_{1j}C_{1j} + a_{2j}C_{2j} + \cdots + a_{nj}C_{nj} \qquad (\text{expansion along column } j)

Every row and every column gives the same answer. For n=2n = 2 and n=3n = 3, expanding along row 1 reproduces the formulas of the previous lesson. For n≥4n \ge 4 we can take this as the definition of det⁡\det.

Strategy: expand along the row or column with the most zeros, because a zero entry kills its whole term.

python · try it yourself
from sympy import Matrix

A = Matrix([[3, 0, 2, -1],
            [1, 2, 0, -2],
            [4, 0, 6, -3],
            [5, 0, 2, 0]])

# column 2 (index 1) has three zeros: only the entry a22 = 2 contributes
M22 = A.minor_submatrix(1, 1)
print("minor submatrix M22:", M22.tolist())
print("M22 =", M22.det(), " C22 =", A.cofactor(1, 1))
print("det via column 2:", A[1, 1] * A.cofactor(1, 1))

# expanding along any row or column gives the same number
rows = [sum(A[i, j] * A.cofactor(i, j) for j in range(4)) for i in range(4)]
cols = [sum(A[i, j] * A.cofactor(i, j) for i in range(4)) for j in range(4)]
print("all rows:", rows, " all columns:", cols, " det:", A.det())
minor submatrix M22: [[3, 2, -1], [4, 6, -3], [5, 2, 0]]
M22 = 10  C22 = 10
det via column 2: 20
all rows: [20, 20, 20, 20]  all columns: [20, 20, 20, 20]  det: 20

A recursive implementation and its cost

Cofactor expansion is a natural recursive function: an n×nn \times n determinant calls nn determinants of size n−1n - 1, each of which calls n−1n - 1 of size n−2n - 2, and so on, down to 1×1. That is about n!n! terms.

python · try it yourself
from math import factorial

calls = 0

def det(M):
    global calls
    calls += 1
    n = len(M)
    if n == 1:
        return M[0][0]
    total = 0
    for j in range(n):
        minor = [row[:j] + row[j + 1:] for row in M[1:]]     # delete row 0 and column j
        total += (-1) ** j * M[0][j] * det(minor)
    return total

for n in range(2, 9):
    calls = 0
    M = [[(i * 7 + j * 3) % 5 + (i == j) for j in range(n)] for i in range(n)]
    d = det(M)
    print(f"n = {n}: det = {d:4d}, recursive calls = {calls:6d}, n! = {factorial(n)}")
n = 2: det =   -5, recursive calls =      3, n! = 2
n = 3: det =   25, recursive calls =     10, n! = 6
n = 4: det = -104, recursive calls =     41, n! = 24
n = 5: det =  451, recursive calls =    206, n! = 120
n = 6: det = 1006, recursive calls =   1237, n! = 720
n = 7: det = 2245, recursive calls =   8660, n! = 5040
n = 8: det = 5005, recursive calls =  69281, n! = 40320

The number of calls grows like e⋅n!e \cdot n!. For n=20n = 20 that is about 6.6×10186.6 \times 10^{18} calls: centuries of computing. Row reduction does the same job in about n3/3n^3/3 operations, 2 700 for n=20n = 20 (Determinants and Row Operations). Application: Cramer's Rule times the difference.

Why expansion along any row works (sketch)

The determinant can be characterised by three properties: it is linear in each row, it changes sign when two rows are swapped, and det⁡I=1\det I = 1. Expansion along row 1 satisfies all three, and moving row ii to the top takes i−1i - 1 swaps, which produces exactly the sign (−1)i+1(-1)^{i+1} that turns row-1 expansion into row-ii expansion. Columns follow from det⁡AT=det⁡A\det A^T = \det A (Properties of Determinants).

In software

  • Symbolic math uses cofactor-style expansion for small matrices with symbolic entries (where division would create messy fractions); for numbers, every serious library uses LU factorisation.
  • Fixed-size 2×2, 3×3, 4×4 code in game math libraries writes out the cofactor expansion explicitly. With n=4n = 4 that is a few dozen multiplications, faster than a general LU routine, and it reuses the 2×2 minors to compute the inverse too (Matrix Inverse).
  • Algorithm analysis: the recursion above is a textbook example of factorial complexity, alongside brute-force traveling salesman.

Exercises

Exercise 1: A minor and a cofactor

For A=[1423−10256]A = \begin{bmatrix} 1 & 4 & 2 \\ 3 & -1 & 0 \\ 2 & 5 & 6 \end{bmatrix}, find M23M_{23} and C23C_{23}.

Answer

M23=−3M_{23} = -3, C23=3C_{23} = 3.

Solution
delete row 2 and column 3→[1425]M23=1⋅5−4⋅2=−3C23=(−1)2+3⋅(−3)=3\begin{aligned} &\text{delete row 2 and column 3} \to \begin{bmatrix} 1 & 4 \\ 2 & 5 \end{bmatrix} \\ M_{23} &= 1 \cdot 5 - 4 \cdot 2 = -3 \\ C_{23} &= (-1)^{2+3} \cdot (-3) = 3 \end{aligned}

Exercise 2: Expand along the best row

Compute det⁡[20130−4152]\det \begin{bmatrix} 2 & 0 & 1 \\ 3 & 0 & -4 \\ 1 & 5 & 2 \end{bmatrix} by expanding along column 2.

Answer

det⁡=55\det = 55.

Solution

Only a32=5a_{32} = 5 is non-zero in column 2, with sign (−1)3+2=−1(-1)^{3+2} = -1:

det⁡=5⋅(−1)⋅det⁡[213−4]=−5⋅(−8−3)=−5⋅(−11)=55\det = 5 \cdot (-1) \cdot \det \begin{bmatrix} 2 & 1 \\ 3 & -4 \end{bmatrix} = -5 \cdot (-8 - 3) = -5 \cdot (-11) = 55
python · try it yourself
from sympy import Matrix
print(Matrix([[2, 0, 1], [3, 0, -4], [1, 5, 2]]).det())
55

Exercise 3: A 4×4 by hand

Compute det⁡[1002030040100005]\det \begin{bmatrix} 1 & 0 & 0 & 2 \\ 0 & 3 & 0 & 0 \\ 4 & 0 & 1 & 0 \\ 0 & 0 & 0 & 5 \end{bmatrix}.

Answer

det⁡=15\det = 15.

Solution

Expand along row 2 (only a22=3a_{22} = 3, sign ++), then along the last row of the 3×3 minor:

det⁡=3⋅det⁡[102410005]=3⋅5⋅det⁡[1041](row 3 of the minor: only 5, sign (−1)3+3=+)=3⋅5⋅1=15\begin{aligned} \det &= 3 \cdot \det \begin{bmatrix} 1 & 0 & 2 \\ 4 & 1 & 0 \\ 0 & 0 & 5 \end{bmatrix} \\ &= 3 \cdot 5 \cdot \det \begin{bmatrix} 1 & 0 \\ 4 & 1 \end{bmatrix} && \text{(row 3 of the minor: only 5, sign } (-1)^{3+3} = +\text{)} \\ &= 3 \cdot 5 \cdot 1 = 15 \end{aligned}

Exercise 4: Count the work

Modify the recursive det so that it skips the recursive call whenever M[0][j] is 0. How many calls does it make on the 4×4 matrix of Exercise 3, compared with 41 without the shortcut?

Answer

8 calls instead of 41: zeros in the first row prune most of the recursion tree.

Solution
python · try it yourself
calls = 0
def det(M):
    global calls
    calls += 1
    if len(M) == 1:
        return M[0][0]
    total = 0
    for j, a in enumerate(M[0]):
        if a == 0:
            continue                      # zero entry: the whole term vanishes
        minor = [row[:j] + row[j + 1:] for row in M[1:]]
        total += (-1) ** j * a * det(minor)
    return total

A = [[1, 0, 0, 2], [0, 3, 0, 0], [4, 0, 1, 0], [0, 0, 0, 5]]
print("det =", det(A), " calls =", calls)
det = 15  calls = 8

Test yourself

What is the sign (−1)i+j(-1)^{i+j} of the cofactor C32C_{32}?

  1. ++
  2. −-
  3. It depends on the entry
  4. 0

Which row or column should you expand along to compute a determinant by hand?

  1. The one with the most zeros
  2. Always the first row
  3. The one with the largest numbers
  4. The main diagonal

How does the work of plain cofactor expansion grow with nn?

  1. Like n2n^2
  2. Like n3n^3
  3. Like 2n2n
  4. Like n!n!