Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How to Learn Reverse Cuthill–McKee: Sparse Matrix Reordering, Bandwidth Reduction, Pseudo-Peripheral Vertices and Solver Locality

Wait, What?

You can make the same sparse linear system much easier to solve without changing a single numerical value—just by renumbering the unknowns.

Reverse Cuthill–McKee (RCM) is a graph-ordering heuristic used to reduce the bandwidth and often the profile of sparse matrices. Its central move is conceptually simple: reinterpret a sparse symmetric matrix as a graph, perform a carefully ordered breadth-first traversal, then reverse the resulting vertex order. The mathematics of the linear system stays the same, but the nonzero pattern can move closer to the main diagonal, improving locality and sometimes reducing storage or factorization work.

Quick Answer

Learn RCM through sparse matrices → graph representation → matrix bandwidth/profile → BFS level structures → degree ordering → pseudo-peripheral starting vertices → reversing the order → permutation matrices → sparse-solver effects → validation and limits. The key professional lesson is that reordering is a representation optimization: it can change computational cost without changing the underlying problem.

1. Start With a Sparse Matrix, Not the Algorithm

A matrix is sparse when most entries are zero. Large finite-element, network, graph-Laplacian and discretized PDE systems often produce sparse matrices because each unknown interacts with only a small local neighbourhood. Sparse algorithms exploit this structure instead of storing or processing every possible entry.

Yet two matrices representing the same system under different variable orderings can have very different-looking nonzero patterns. That is where ordering algorithms matter.

2. What Is Bandwidth?

For a sparse matrix A, bandwidth measures how far nonzero entries lie from the main diagonal. A common symmetric definition is:

bandwidth(A) = max{|i - j| : A[i,j] != 0}

If all nonzeros sit close to the diagonal, the matrix has small bandwidth. If some nonzeros are far away, the bandwidth grows. Profile or envelope measures a related but more detailed notion of how far the first nonzero in each row extends from the diagonal.

3. Turn the Matrix Into a Graph

For a structurally symmetric sparse matrix, create one graph vertex for each row/column. Add an edge between vertices i and j whenever A[i,j] is structurally nonzero. Now matrix reordering becomes graph relabeling.

A permutation P transforms A into:

A' = P A P^T

The numerical problem is equivalent, but the positions of the nonzeros move.

4. Learn Cuthill–McKee Before Reversing It

The original Cuthill–McKee method performs a breadth-first traversal, but when several unvisited neighbours are available, it processes lower-degree vertices first. This tends to keep level structures narrow and bring graph-adjacent vertices closer together in the numbering.

queue = [start]
order = []
mark start visited

while queue not empty:
    v = pop_front(queue)
    append v to order

    candidates = unvisited_neighbors(v)
    sort candidates by increasing degree

    for u in candidates:
        mark u visited
        push_back(queue, u)

For disconnected graphs, run the process separately on each connected component.

5. Why Reverse the Order?

RCM simply reverses the Cuthill–McKee ordering. Empirically and theoretically, reversing often improves the profile or envelope even when the matrix bandwidth is unchanged. This can reduce storage and work for certain elimination schemes.

A useful beginner exercise is to generate a Cuthill–McKee order, reverse it, then draw both permuted sparsity patterns. The graph has not changed. Only the labels have.

6. Starting Vertices Matter

A poor BFS start can create a wide level structure. Practical RCM implementations therefore often begin near a pseudo-peripheral vertex: a vertex intended to behave like an endpoint of a long graph diameter. Exact peripheral-vertex computation can be costly, so repeated level-structure heuristics are used.

A common pattern is: choose a low-degree vertex, build BFS levels, move to a low-degree vertex in the last level, rebuild, and continue until the level depth stops increasing. This does not guarantee the true diameter endpoint, but it usually gives a good starting point.

7. Work a Small Example

Take six graph vertices with edges forming a chain plus two cross-links. Number them deliberately badly so one edge connects index 1 to index 6. Write the adjacency matrix and calculate its bandwidth. Then run degree-ordered BFS, reverse the resulting order, apply the permutation, and calculate bandwidth again.

This hand calculation teaches what RCM actually optimizes. It is not “sorting rows.” It is trying to place graph-near unknowns numerically near one another.

8. Current SciPy Behaviour

Current SciPy documentation exposes scipy.sparse.csgraph.reverse_cuthill_mckee for CSR and CSC sparse arrays or matrices. The function returns a permutation array. When symmetric_mode=False, SciPy treats the structure through A+Aᵀ; when the matrix is structurally symmetric, symmetric_mode=True avoids that symmetrization step.

This is an engineering detail worth understanding because “symmetric numerically” and “symmetric structurally” are not always the same question.

9. What RCM Can Improve

  • matrix bandwidth;
  • profile or envelope;
  • memory locality;
  • banded storage requirements;
  • some sparse factorization costs;
  • cache behaviour in operations that benefit from closer structural locality.

But RCM does not guarantee the globally minimum bandwidth. Minimum-bandwidth ordering is a difficult combinatorial problem, so RCM is a fast heuristic.

10. RCM Is Not Always the Best Sparse Ordering

Modern sparse direct solvers often care more about fill-in than raw bandwidth. During LU or Cholesky factorization, new nonzeros may appear. Minimum-degree, approximate minimum-degree and nested-dissection orderings are often designed specifically to reduce fill. An RCM permutation can therefore look visually tidy yet lose to another ordering in actual factorization time.

Professional benchmarking should compare the metric that matters: factor nonzeros, memory, solve time, preprocessing time and downstream locality—not just a pretty sparsity plot.

11. Complexity and Data Structures

RCM is fundamentally built on BFS plus local degree ordering. With efficient adjacency structures and degree handling, it is inexpensive compared with the sparse factorization it often precedes. The exact complexity expression depends on implementation and neighbour sorting strategy. Boost’s graph documentation, for example, describes a complexity involving |E| and the maximum degree.

In practical code, avoid repeatedly scanning dense rows. Work directly with sparse adjacency structures.

12. How to Learn It Efficiently

Use a Predict–Run–Investigate–Modify–Make progression. Predict which graph labels cause large bandwidth. Run a simple bandwidth calculator. Investigate a BFS level structure. Modify the neighbour order by degree. Then make the reverse permutation and compare results. Only after the mechanism is clear should you call SciPy or Boost.

Parsons-style reconstruction works well here because the algorithm has a small number of meaningful subgoals: choose start, BFS, degree-order neighbours, concatenate components, reverse order, apply permutation, validate.

Common Failure States

  • Reordering rows without applying the corresponding column permutation.
  • Confusing numerical values with structural nonzeros.
  • Assuming RCM minimizes bandwidth exactly.
  • Ignoring disconnected components.
  • Starting BFS from an arbitrary high-degree central vertex and then blaming the heuristic.
  • Measuring only bandwidth when the real goal is sparse-factorization fill or wall-clock time.
  • Applying a symmetric-structure algorithm without understanding how an unsymmetric matrix is being symmetrized.

Practice Ladder

  • Beginner: calculate bandwidth for several 5×5 sparse matrices.
  • Foundation: convert a sparse matrix pattern to a graph and run degree-ordered BFS.
  • Intermediate: implement Cuthill–McKee and RCM for disconnected graphs.
  • Advanced: add a pseudo-peripheral start heuristic and compare resulting profiles.
  • Professional: benchmark natural ordering, RCM, approximate minimum degree and nested dissection on sparse PDE or finite-element matrices using bandwidth, fill, memory and solve time.

Learning Hall Boundary

This article owns Reverse Cuthill–McKee as sparse-matrix/graph reordering for bandwidth and profile reduction. It does not replace the existing numerical linear algebra, graph traversal, matrix multiplication, shortest-path or general sparse-solver material.

Evidence Boundary

Elizabeth Cuthill and James McKee introduced the bandwidth-reduction method in “Reducing the bandwidth of sparse symmetric matrices” at ACM 1969. Later analyses explain why reversing the order often improves envelope/profile behaviour. Current SciPy 1.18 documentation continues to expose RCM directly for sparse graph structures, and the Boost Graph Library documents degree-ordered BFS and pseudo-peripheral starting strategies.

Professional rule: you understand RCM when you can explain the permutation as a graph relabeling, predict how it changes the sparsity pattern, and prove its value using the downstream metric that actually matters.