Tutorials › Linear Algebra › Counting Operations in Gaussian Elimination

LU Factorization and Numerical Considerations · Tutorial 912 of 1000

Counting Operations in Gaussian Elimination

Learn how the dimensions of each elimination stage determine the exact arithmetic count and its cubic growth.

Intermediate 9 min read

What You'll Learn

  • Count the multipliers and trailing-matrix updates at each elimination stage.
  • Derive exact formulas for divisions, multiplications, subtractions and their total.
  • Identify the cubic leading term and distinguish it from lower-order costs.
  • Estimate arithmetic work for matrices of several sizes.
  • Separate scalar arithmetic counts from pivot searches and row exchanges.

Why Count Elimination Operations?

Gaussian elimination turns a matrix into upper-triangular form through a sequence of stages. Each stage works on a smaller trailing part of the matrix than the one before it. Counting the arithmetic at those stages explains why elimination on an \(n\times n\) matrix becomes costly as \(n\) grows, and why its dominant work scales cubically rather than quadratically.

We will count scalar additions, subtractions, multiplications and divisions. Each counts as one arithmetic operation. In particular, updating an entry by \(a_{ij}\leftarrow a_{ij}-\ell_{ik}u_{kj}\) costs one multiplication and one subtraction, or two operations. This is the usual scalar-operation convention; it is not a count of processor instructions or elapsed time.

Counting assumptions: Let \(n\in\mathbb{N}\). Count the arithmetic needed to eliminate the entries below the pivots of an \(n\times n\) coefficient matrix, assuming all \(n-1\) stages can be completed. At each stage, count divisions for the elimination multipliers and multiplications and subtractions for matrix updates. Do not count pivot-search comparisons, row exchanges, or updates to a right-hand-side column.

If a pivot is zero, an exchange of rows may be needed, or elimination may stop if no suitable pivot is available. The count below describes a completed elimination; it applies, for example, when row exchanges allow the process to continue through all stages. Pivot searches and exchanges are separate from the scalar-arithmetic count. Their cost is not included here.

What Happens at One Stage?

Number the pivots \(k=1,\dots,n-1\). At stage \(k\), the pivot is in column \(k\), and the rows below it are updated to make their entries in that column zero. There are \(n-k\) such rows. For each row \(i>k\), the multiplier is \(\ell_{ik}=a_{ik}/u_{kk}\), which takes one division. Thus stage \(k\) uses \(n-k\) divisions.

After calculating a multiplier, elimination updates the entries to the right of the pivot. There are \(n-k\) remaining columns and \(n-k\) rows below the pivot, so the trailing block being updated has \((n-k)^2\) entries. Each entry requires one multiplication and one subtraction. Therefore, at stage \(k\), there are \((n-k)^2\) multiplications and the same number of subtractions.

Worked Example: Count the Operations for a 3 by 3 Matrix

First track the count stage by stage. For \(n=3\), stage 1 has two rows below the pivot and two columns to the right. It therefore uses \(2\) divisions, \(4\) multiplications and \(4\) subtractions. Stage 2 has one row below the pivot and one column to the right, so it uses \(1\) division, \(1\) multiplication and \(1\) subtraction. The total is \(3\) divisions, \(5\) multiplications and \(5\) subtractions: \(13\) arithmetic operations.

For a concrete check, eliminate the following matrix without row exchanges. At stage 1 the multipliers are \(4/2=2\) and \(8/2=4\). The two row updates are shown entry by entry:

$$ \begin{bmatrix}2&1&1\\4&3&3\\8&7&9\end{bmatrix} \longrightarrow \begin{bmatrix}2&1&1\\0&3-2(1)&3-2(1)\\0&7-4(1)&9-4(1)\end{bmatrix} = \begin{bmatrix}2&1&1\\0&1&1\\0&3&5\end{bmatrix}. $$

At stage 2 the multiplier is \(3/1=3\), and the remaining entry changes from \(5\) to \(5-3(1)=2\). Thus the upper-triangular matrix is \(\begin{bmatrix}2&1&1\\0&1&1\\0&0&2\end{bmatrix}\). The actual work agrees with the count: stage 1 used two divisions and four multiply-subtract updates, and stage 2 used one division and one update. Counting the multiplication and subtraction in each update separately gives \(2+8+1+2=13\) operations.

Check: The multipliers give \(\mathbf{L}=\begin{bmatrix}1&0&0\\2&1&0\\4&3&1\end{bmatrix}\) and the resulting triangular matrix is \(\mathbf{U}=\begin{bmatrix}2&1&1\\0&1&1\\0&0&2\end{bmatrix}\). Multiplication gives \(\mathbf{L}\mathbf{U}=\begin{bmatrix}2&1&1\\4&3&3\\8&7&9\end{bmatrix}\), the original matrix. The elimination and its operation count are consistent.

Summing the Stage Counts

As the stage index \(k\) increases, the number \(n-k\) runs through \(n-1,n-2,\dots,1\). So the total divisions are the sum of these integers, while the total multiplications and subtractions are each the sum of their squares.

Lemma: For every positive integer \(m\), \(\sum_{j=1}^{m}j=m(m+1)/2\) and \(\sum_{j=1}^{m}j^2=m(m+1)(2m+1)/6\).

Proof. Both identities hold for \(m=1\): the sums are \(1\), and the formulas also give \(1\). Suppose they hold for \(m\). For the first identity, adding the next term gives \(m(m+1)/2+(m+1)=(m+1)(m+2)/2\). For the sum of squares, adding \((m+1)^2\) gives

$$ \frac{m(m+1)(2m+1)}{6}+(m+1)^2 =\frac{(m+1)\bigl(m(2m+1)+6(m+1)\bigr)}{6} =\frac{(m+1)(m+2)(2m+3)}{6}. $$

These are exactly the two formulas with \(m+1\) in place of \(m\). By induction, both identities hold for every positive integer \(m\). \(\square\)

Theorem (Exact operation count): Under the counting assumptions above, elimination on an \(n\times n\) matrix uses \(n(n-1)/2\) divisions, \(n(n-1)(2n-1)/6\) multiplications and the same number of subtractions. Its total scalar-arithmetic count is $$ C_n=\frac{n(n-1)(2n-1)}{3}+\frac{n(n-1)}{2} =\frac{2}{3}n^3-\frac{1}{2}n^2-\frac{1}{6}n. $$

Proof. At stage \(k\), there are \(n-k\) divisions and \((n-k)^2\) multiplications and subtractions. Summing over \(k=1,\dots,n-1\), and writing \(j=n-k\), the division count is \(\sum_{j=1}^{n-1}j\). By the lemma, it equals \(n(n-1)/2\). The multiplication count is \(\sum_{j=1}^{n-1}j^2\), which by the lemma equals \(n(n-1)(2n-1)/6\); the subtraction count is identical because each update has one of each. Adding all three counts gives twice the sum of squares plus the sum of integers, namely \(n(n-1)(2n-1)/3+n(n-1)/2\). Expanding the products yields \(C_n=2n^3/3-n^2/2-n/6\), as claimed. When \(n=1\), there are no stages, and this formula gives \(C_1=0\), so it also covers that case. \(\square\)

The Cubic Growth Term

The exact expression contains a cubic term, a quadratic term and a linear term. For large \(n\), the cubic term dominates: the leading operation count is \(\frac{2}{3}n^3\). This does not mean the exact count is \(\frac{2}{3}n^3\); the lower-order terms give a correction, which can matter for moderate matrix sizes.

The coefficient \(2/3\) follows from the counting convention. The trailing updates involve about \(n^3/3\) entries in total, and each entry takes two arithmetic operations. If one groups a multiplication and subtraction together as a single update, there are about \(n^3/3\) such updates instead. These are different ways of reporting the work, so a count must say which convention it uses.

Worked Example: Estimate the Work for a 100 by 100 Matrix

There are \(99\) elimination stages. The number of updates of trailing-matrix entries is

$$ \sum_{j=1}^{99}j^2 =\frac{99\cdot100\cdot199}{6} =328{,}350. $$

Thus there are \(328{,}350\) multiplications and \(328{,}350\) subtractions. Together, the updates use \(656{,}700\) arithmetic operations. The division count is \(99\cdot100/2=4{,}950\). The total is therefore \(656{,}700+4{,}950=661{,}650\) operations.

Check: Substitution into the expanded formula gives \(C_{100}=(2/3)(1{,}000{,}000)-(1/2)(10{,}000)-(1/6)(100)=666{,}666\frac{2}{3}-5{,}000-16\frac{2}{3}=661{,}650\). Equivalently, the combined update count is \(100\cdot99\cdot199/3=1{,}970{,}100/3=656{,}700\), consistent with the stage sum.

Worked Example: Estimate the Work for a 1000 by 1000 Matrix

For \(n=1000\), the combined multiplication-and-subtraction count is

$$ \frac{1000\cdot999\cdot1999}{3} =\frac{1{,}997{,}001{,}000}{3} =665{,}667{,}000. $$

The division count is \(1000\cdot999/2=499{,}500\), so the total is \(665{,}667{,}000+499{,}500=666{,}166{,}500\) arithmetic operations. The leading-term estimate alone is \((2/3)(1000)^3=666{,}666{,}666\frac{2}{3}\), close to the exact count but not equal to it.

Check: The exact formula gives \(C_{1000}=(2/3)(1{,}000{,}000{,}000)-(1/2)(1{,}000{,}000)-(1/6)(1000)=666{,}666{,}666\frac{2}{3}-500{,}000-166\frac{2}{3}=666{,}166{,}500\). The stage-sum and polynomial calculations agree.

Interpreting the Estimate

A cubic leading term has a practical consequence: multiplying the matrix size by a factor of \(r\) multiplies the leading estimate by \(r^3\). For example, increasing \(n\) from \(100\) to \(1000\) multiplies the leading estimate by \(10^3=1000\). The exact totals above have a ratio of about \(1007\), because the lower-order terms have a larger relative effect at \(n=100\).

An operation count is a model of arithmetic work, not a direct prediction of runtime. Actual time also depends on the computer, implementation, memory movement, parallel execution and the rate at which operations are completed. For instance, at a hypothetical sustained rate of \(10^9\) counted operations per second, the \(1000\times1000\) count corresponds to \(666{,}166{,}500/10^9=0.6661665\) seconds. This is an estimate under that assumed rate, not a guarantee of elapsed time.

The calculation also excludes pivot selection. In partial pivoting, choosing a pivot involves comparing candidate entries, and row exchanges rearrange rows. Those tasks are not scalar additions, subtractions, multiplications or divisions in our count. The central cubic term describes the trailing-matrix arithmetic; it should not be mistaken for a complete accounting of every implementation cost.

Common Counting Pitfalls

Counting each update as only one arithmetic operation. The update \(a_{ij}\leftarrow a_{ij}-\ell_{ik}u_{kj}\) contains a multiplication and a subtraction. Under the scalar-operation convention used here, that is two operations. Calling it one update is fine if the unit is stated, but it gives a different total from counting scalar arithmetic.

Using the wrong stage size. Stage \(k\) updates a square trailing block of size \((n-k)\times(n-k)\), not an \(n\times n\) block at every stage. For \(n=4\), the update counts by stage are \(3^2=9\), \(2^2=4\), and \(1^2=1\), for \(14\) updates total. Adding \(9+4+1=14\) directly checks the sum-of-squares formula.

Mixing the leading estimate with the exact count. For \(n=100\), the leading term is \(666{,}666\frac{2}{3}\), while the exact count is \(661{,}650\). The leading term is useful for describing large-scale growth; the exact formula is needed when a precise count is requested.

Check Your Understanding

Use the convention that each multiplication, subtraction and division counts as one scalar-arithmetic operation.

  1. For an \(8\times8\) matrix, how many divisions occur at stage \(k=3\)? How many trailing entries are updated at that stage?
  2. For \(n=5\), calculate the total number of updates, then the total number of scalar-arithmetic operations including divisions.
  3. Explain why the multiplication count equals the subtraction count in this model.
  4. What is the leading operation count for an \(n\times n\) matrix, and why is it not the exact count?
  5. Name two types of work excluded from the scalar-arithmetic count defined here.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon