Algorithm Search⌘K

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; nn vertices, mm edges, largest degree Δ\Delta. Let nCn_C and mCm_C be the vertex and edge counts of a component CC.

Numbering (lines L1 to L10 except L3). Line L1 is O(n)O(n). Sorting all vertices by (d,index)(d, \text{index}) for line L2 is O(nlog⁡n)O(n \log n). In the inner loop, each vertex is processed once at line L7 (Theorem 1 of the correctness proof); processing vv scans its d(v)d(v) neighbours and sorts at most d(v)d(v) of them, O(d(v)log⁡(d(v)+1)+1)O(d(v) \log(d(v) + 1) + 1). Summing over vv, with ∑vd(v)=2m\sum_v d(v) = 2m and log⁡(d(v)+1)≤log⁡(Δ+1)\log(d(v)+1) \le \log(\Delta + 1), gives O(n+mlog⁡Δ)O(n + m \log \Delta). Total O(nlog⁡n+mlog⁡Δ)O(n \log n + m \log \Delta). (With a counting sort by degree, both sorts are linear and the numbering is O(n+m)O(n + m).)

Root search (line L3). One level structure of CC costs O(nC+mC)O(n_C + m_C), and choosing the minimum degree vertex of the last level is O(nC)O(n_C). By Lemma 1 of the correctness proof there are at most e+1≤nCe + 1 \le n_C level structures. So line L3 costs O(nC(nC+mC))O(n_C (n_C + m_C)) for CC, and summing over components, O(n(n+m))O(n (n + m)). Adding the numbering, the worst case time is O(n(n+m))O(n(n + m)).

Space. The flags take nn words, π\pi (which is also the queue) nn words, one level structure and the visited set of a search O(n)O(n) words, and the sorted neighbour list at line L8 at most Δ≤n\Delta \le n words. So Θ(n)\Theta(n) extra space, besides the input. ■\blacksquare

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: G=(V,E)G = (V, E) undirected, n=∣V∣n = |V|, π\pi the output list, f(πk)=kf(\pi_k) = k. For a root rr, Li(r)L_i(r) is the set of vertices at distance ii from rr, e(r)e(r) the eccentricity, and "levels from rr" means L0(r),…,Le(r)(r)L_0(r), \ldots, L_{e(r)}(r).

Lemma 1 (the root search terminates). PSEUDO-PERIPHERAL(G,s)(G, s) stops after at most nn level structure computations and returns a vertex of the component of ss.

Proof. Each accepted move replaces rr by a vertex xx of the same component with e(x)>e(r)e(x) > e(r). Eccentricities are integers in [0,n−1][0, n - 1], so there are at most n−1n - 1 accepted moves, and each iteration computes one level structure. Every xx is taken from a level of the current structure, which lies in the component. □\square

Lemma 2 (each vertex is appended once). A vertex is appended to π\pi only at line L4 or L9, and in both cases seen\mathrm{seen} 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 rr ends, the vertices appended during it are exactly the component C(r)C(r) of rr, and they are appended in breadth-first order: all of Li(r)L_i(r) before any of Li+1(r)L_{i+1}(r).

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 C(r)C(r) is seen. Lines L6 to L9 are a breadth-first search from rr that uses π\pi 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 LiL_i followed by vertices of Li+1L_{i+1}. Hence the vertices are appended in nondecreasing order of distance, and every vertex reachable from rr, that is every vertex of C(r)C(r), is appended. No vertex outside C(r)C(r) is adjacent to C(r)C(r), so none is appended. □\square

Theorem 1 (permutation, termination). The algorithm terminates and π\pi is a permutation of VV.

Proof. The outer loop of line L2 has nn iterations. Each inner loop advances head by one per iteration and stops when head reaches ∣π∣≤n|\pi| \le n (Lemma 2). Each call of line L3 terminates by Lemma 1. Every vertex ss is either seen when line L2 reaches it, hence already in π\pi, or it becomes a root's component member by Lemma 3; so all nn vertices appear, and by Lemma 2 exactly once. □\square

Theorem 2 (characterization). Let CC be a component with root rr, numbered f(r)=c,c+1,…,c+∣C∣−1f(r) = c, c + 1, \ldots, c + |C| - 1. For v∈C∖{r}v \in C \setminus \{r\} let p(v)=min⁡{f(w):w∼v}p(v) = \min\{f(w) : w \sim v\}. Then p(v)<f(v)p(v) < f(v), and listing C∖{r}C \setminus \{r\} in the order of π\pi lists the keys (p(v),d(v),v)(p(v), d(v), v) in strictly increasing order. Conversely, a numbering of CC that starts with rr and has this property is the one produced.

Proof. Contiguity follows from Lemma 3, since a component is appended in one inner loop. Fix v≠rv \ne r. It is appended at line L9 while some vertex uu is being processed at line L7. Every neighbour of vv processed before uu would have appended vv earlier, so none exists, and uu itself is a neighbour; vertices are processed in the order of their numbers, so uu is the neighbour with the smallest number and p(v)=f(u)<f(v)p(v) = f(u) < f(v). Vertices appended while processing the same uu have the same pp and are appended in increasing (d,index)(d, \text{index}) order by line L8. Vertices appended while processing uu come before those appended while processing a later u′u', which have p=f(u′)>f(u)p = f(u') > f(u). So the keys increase strictly along π\pi. For the converse, the keys are distinct (they contain vv), so the property fixes the order of C∖{r}C \setminus \{r\} once ff is known on earlier vertices; by induction on position this order is unique, and the produced order has it. □\square

Theorem 3 (bandwidth bound). With the levels L0,…,LeL_0, \ldots, L_e from the root of a component, every edge {v,w}\{v, w\} of that component satisfies ∣f(v)−f(w)∣≤max⁡i(∣Li∣+∣Li+1∣)−1|f(v) - f(w)| \le \max_i (|L_i| + |L_{i+1}|) - 1, with the convention ∣Le+1∣=0|L_{e+1}| = 0. Hence βf≤2w−1\beta_f \le 2 w - 1 where ww 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 v,w∈Li∪Li+1v, w \in L_i \cup L_{i+1} for some ii. By Lemma 3, Li∪Li+1L_i \cup L_{i+1} occupies a contiguous block of ∣Li∣+∣Li+1∣|L_i| + |L_{i+1}| numbers. Two numbers in a block of that size differ by at most ∣Li∣+∣Li+1∣−1|L_i| + |L_{i+1}| - 1. Edges join vertices of the same component only, so the bound for GG is the maximum over components, which is at most 2w−12w - 1. ■\blacksquare

Back to Cuthill-McKee algorithm