Proofs: Cuthill-McKee algorithm
These are the human proofs of Cuthill-McKee algorithm, at full length.
Cost of the Cuthill-McKee ordering full
This proof shows: time.worst, space.extra, numbering.worst.
Adjacency lists with degrees stored; vertices, edges, largest degree . Let and be the vertex and edge counts of a component .
Numbering (lines L1 to L10 except L3). Line L1 is . Sorting all vertices by for line L2 is . In the inner loop, each vertex is processed once at line L7 (Theorem 1 of the correctness proof); processing scans its neighbours and sorts at most of them, . Summing over , with and , gives . Total . (With a counting sort by degree, both sorts are linear and the numbering is .)
Root search (line L3). One level structure of costs , and choosing the minimum degree vertex of the last level is . By Lemma 1 of the correctness proof there are at most level structures. So line L3 costs for , and summing over components, . Adding the numbering, the worst case time is .
Space. The flags take words, (which is also the queue) words, one level structure and the visited set of a search words, and the sorted neighbour list at line L8 at most words. So extra space, besides the input.
Cuthill-McKee numbers every vertex once, follows the level structure, and has bandwidth below twice the level width full
This proof shows: correctness, termination.
Notation of the page: undirected, , the output list, . For a root , is the set of vertices at distance from , the eccentricity, and "levels from " means .
Lemma 1 (the root search terminates). PSEUDO-PERIPHERAL stops after at most level structure computations and returns a vertex of the component of .
Proof. Each accepted move replaces by a vertex of the same component with . Eccentricities are integers in , so there are at most accepted moves, and each iteration computes one level structure. Every is taken from a level of the current structure, which lies in the component.
Lemma 2 (each vertex is appended once). A vertex is appended to only at line L4 or L9, and in both cases is false just before and set to true at that moment. Since seen is never reset, no vertex is appended twice.
Lemma 3 (one component per root). When the loop of lines L6 to L9 for root ends, the vertices appended during it are exactly the component of , and they are appended in breadth-first order: all of before any of .
Proof. Before the root is chosen at line L3, every seen vertex belongs to a component already processed (induction over the outer loop, using the claim for earlier roots), so no vertex of is seen. Lines L6 to L9 are a breadth-first search from that uses from position head as its queue: a vertex is appended when it is first discovered from an already appended vertex, and vertices are removed in the order appended. The standard BFS invariant holds: the queue, read from head to the end, consists of vertices of some level followed by vertices of . Hence the vertices are appended in nondecreasing order of distance, and every vertex reachable from , that is every vertex of , is appended. No vertex outside is adjacent to , so none is appended.
Theorem 1 (permutation, termination). The algorithm terminates and is a permutation of .
Proof. The outer loop of line L2 has iterations. Each inner loop advances head by one per iteration and stops when head reaches (Lemma 2). Each call of line L3 terminates by Lemma 1. Every vertex is either seen when line L2 reaches it, hence already in , or it becomes a root's component member by Lemma 3; so all vertices appear, and by Lemma 2 exactly once.
Theorem 2 (characterization). Let be a component with root , numbered . For let . Then , and listing in the order of lists the keys in strictly increasing order. Conversely, a numbering of that starts with and has this property is the one produced.
Proof. Contiguity follows from Lemma 3, since a component is appended in one inner loop. Fix . It is appended at line L9 while some vertex is being processed at line L7. Every neighbour of processed before would have appended earlier, so none exists, and itself is a neighbour; vertices are processed in the order of their numbers, so is the neighbour with the smallest number and . Vertices appended while processing the same have the same and are appended in increasing order by line L8. Vertices appended while processing come before those appended while processing a later , which have . So the keys increase strictly along . For the converse, the keys are distinct (they contain ), so the property fixes the order of once is known on earlier vertices; by induction on position this order is unique, and the produced order has it.
Theorem 3 (bandwidth bound). With the levels from the root of a component, every edge of that component satisfies , with the convention . Hence where is the largest level width over all components.
Proof. In a breadth-first level structure, the endpoints of an edge are at distances differing by at most one, so for some . By Lemma 3, occupies a contiguous block of numbers. Two numbers in a block of that size differ by at most . Edges join vertices of the same component only, so the bound for is the maximum over components, which is at most .