Algorithm Search⌘K

Proofs: Boyer-Myrvold planarity test

These are the human proofs of Boyer-Myrvold planarity test, at full length.

Correctness of the Boyer-Myrvold planarity test sketch

This proof shows: correctness, termination.

Line numbers refer to the pseudocode on the main page. Vertices are their preorder numbers in the search of line L2. Soundness (an output rotation system is planar) and the main invariant are proved in full. Completeness (if line L7 fails, the graph is not planar) is proved for the Minors A, B and C below; for the remaining cases the proof follows the case analysis of Boyer and Myrvold (2004) and only states it, so this file has the status of a sketch.

Setting

The embedded graph G~\tilde G is the set of tree edges and of back edges embedded so far, with each component stored as a rotation system: a cyclic list of edges at each node, read in one direction for the component. A node is a vertex or a root copy rcr_c. Step vv means one round of lines L5 to L7. A component is a connected part of G~\tilde G that is joined to the rest only through root copies, so its root copy rcr_c is the only node of it that stands for a vertex outside the subtree T(c)T(c).

Fact 1. At the start of step vv, every back edge (u,w)(u, w) with u>vu > v is embedded, and none with u≤vu \le v is. Every component has the form: a root copy rcr_c, and a set of vertices of T(c)T(c) that includes cc.

Proof. Line L3 creates one component per tree edge. A step uu embeds only back edges (u,w)(u, w) (line L17 with R=rcR = r_c a copy of uu), and by line L7 it embeds all of them or the run ends. A merge (line L25) puts a component with root copy rc′r_{c'}, where c′c' is a child of a vertex ww of the component, into the component of ww, and T(c′)⊂T(c)T(c') \subset T(c). □\square

Soundness

Lemma 1. Every component of G~\tilde G is a plane embedding at all times, and its external face is the face that lines L12, L15, L19 and L21 walk along.

Proof. By induction over the operations. A new component rc−cr_c - c is one edge, which is planar, and its external face holds both nodes.

Embedding an edge (line L17). When (R,w)(R, w) is embedded on side dd, the walk has reached ww from RR along side dd of the external face, through components that were merged into one just before (the stack SS is emptied first). So RR and ww are both on the external face of one component, and the new edge is drawn in the external face, next to the part of the boundary that the walk went along. A curve in the outer face between two points of its boundary crosses nothing, so the result is plane. The new external face is the old one with the walked part between RR and ww replaced by the new edge.

Merging (lines L24 and L25). The root copy rr is a copy of ww, and ww is on the external face of its component. Putting the whole component of rr into the corner of the external face at ww, between the edge by which the walk came and the next one, and then identifying rr with ww, glues two plane embeddings at one point of their outer faces; this is plane. Its external face is the old external face with the boundary of the component of rr inserted at ww.

Flipping (line L24). Reversing every list of a component gives the mirror image of its embedding, which is plane and has the same faces. The code reverses only the list of rr and records sign(c)=−1\mathrm{sign}(c) = -1; the lists of the other vertices of the component are taken as reversed. The walk reads lists from both ends and keeps the side by which it entered each node, so it reads the external face of the true embedding in both cases.

The final join and orientation (lines L8 and L9). Line L8 glues the remaining components at their root copies, as in a merge, which is plane. In the end, a vertex uu lies in the component that was flipped by every flip on its tree path, and only those: a flip of the component of rcr_c flips the vertices of T(c)T(c) that were in it, and later merges carry them along. So the true list of uu is the stored list reversed exactly when the product of signs from the root to uu is −1-1, which is what line L9 does. □\square

Theorem 1 (soundness). If BM-PLANAR returns a rotation system, then it is a planar embedding of GG.

Proof. All tree edges are embedded by line L3, and every back edge by line L7 (a back edge (v,w)(v, w) is checked at step vv). No other edge is ever added, and each edge is added once. By Lemma 1, the result is a plane embedding with every edge of GG. □\square

The main invariant

Being pertinent or externally active with respect to a step uu means that ww has a path to a vertex a≤ua \le u that is an ancestor of uu, made of edges that are not embedded yet, apart from tree edges into the subtree of a separate child of ww.

Lemma 2 (invariant). After step vv, every vertex that is pertinent or externally active with respect to v−1v - 1 is on the external face of its component.

Proof. Being active with respect to v−1v - 1 means having a connection to a vertex u<vu < v, so it implies being externally active with respect to vv. Activity only goes down as the steps go on, because embedded edges are not counted and the threshold vv goes down. Before step n−1n - 1 every component is a single edge, so the claim holds. Assume it holds before step vv.

A vertex leaves the external face only when an edge (R,z)(R, z) is embedded at line L17: the nodes on the walked part of the boundary between the previous point and zz go inside. Each of these nodes was passed by the walk of this step. The walk passes a node only in three ways: at line L21, which requires it to be not externally active; through line L20, where every node between rr and the choice is inactive by the definition of "first active node"; or after the node has had its pertinent edges handled and is not externally active (lines L17 to L21 in order). In the last case of line L20, the walk goes down into a child component rr of ww; then ww stays on the external face, because the merge inserts the boundary of the component of rr at ww, and the walked side ends at zz while the other side comes back to ww. So every node closed in at step vv is not externally active with respect to vv, and so not active with respect to v−1v - 1. Nodes in the components that are not touched keep their place. □\square

Lemma 2 also justifies WALKUP: at step vv, a pertinent vertex is active with respect to vv, so by Lemma 2 for step v+1v + 1 it is on the external face of its component, and walking along that face from it reaches the root copy.

Termination

The outer loop has nn rounds. WALKUP stops at the first node marked in the same step, and every round of its loop marks a new node. In WALKDOWN, every round of line L16 either embeds an edge, merges components, moves to a new node of the external face, or leaves the loop; the walk never passes the root RR, and a component can be entered from a root copy only while that root copy is in a list of pertinent roots, from which line L25 removes it. Every list operation is bounded by the number of edges. So the run ends.

Completeness

Assume line L7 fails at step vv: a back edge (v,w0)(v, w_0) with w0∈T(c)w_0 \in T(c) for a child cc of vv is not embedded after WALKDOWN(v,rc)(v, r_c). For each of the cases below we find a subdivision of K3,3K_{3,3} or K5K_5 in GG, so GG is not planar by Kuratowski's theorem (only the easy direction is used: such a subgraph cannot be drawn without crossings).

Connections. Three kinds of paths outside the current component are used. If xx is externally active, there is a path PxP_x from xx to a vertex ax<va_x < v that is a proper ancestor of vv: a back edge from xx, or a path into the subtree of a separate child of xx and then a back edge. If ww is pertinent, there is such a path PwP_w from ww to vv. These paths leave the component only through the subtree of a separate child, or by a single back edge, so paths from different vertices of a component are disjoint except at their ends in the ancestors of vv. Let ZZ be the tree path between the smallest and the largest of the ends axa_x; all of it is below vv, and the tree path from vv up to the largest end joins vv to ZZ. In the subdivisions below, ZZ is one branch vertex: take the largest end as the vertex and the rest of ZZ as parts of the paths into it.

Lemma 3 (end state). One of the following holds.

  1. (Blocked in a child.) WALKDOWN returned at line L23. Then there is a component DD whose root copy rr is a copy of a vertex u≠vu \ne v, two nodes x≠yx \ne y on its external face that are externally active and not pertinent, and a pertinent vertex ww on the part of the external face of DD from xx to yy that does not contain rr.
  2. (Blocked at the root.) Both walks of line L14 stopped at line L22, at xx for side 0 and at yy for side 1, with x≠yx \ne y. The component BB of rcr_c has a pertinent vertex ww on the part of its external face from xx to yy that does not contain rcr_c, and all nodes strictly between rcr_c and xx, and strictly between rcr_c and yy, are inactive.

Proof. In case 1, let DD be the component of the last entry pushed on SS. After that push, the walk went to the choice of line L20 and stopped there with SS not empty. If the choice were pertinent, line L17 would embed an edge and empty SS, or line L18 would push again. So the choice is not pertinent, and by the choice rule neither is the other first active node; both are active, so both are externally active. The root copy rr was in a list of pertinent roots, so WALKUP of this step passed through DD from a pertinent node on its external face (Lemma 2), and DD was not changed since. That node is not inactive, so it is not between rr and xx or between rr and yy; it is not xx or yy either. If x=yx = y, every other node on the external face is between rr and xx on one side, which is impossible, so x≠yx \ne y. The root copy rr is a copy of the vertex w′w' whose entry was pushed; w′w' is in the subtree of cc, so w′≠vw' \ne v.

In case 2, the last edge embedded on side 0 closes in everything walked before it, and every node walked after it was passed at line L21, so it is inactive. The walk stopped at xx, which is externally active and, after its edges were handled, not pertinent; the same holds for side 1. The edge (v,w0)(v, w_0) was recorded by WALKUP through a node on the external face of BB that is pertinent and was never reached by either walk, so it lies on the part from xx to yy, and x≠yx \ne y as in case 1. □\square

Minor A. In case 1, GG contains a subdivision of K3,3K_{3,3} with parts {u,w,Z}\{u, w, Z\} and {x,y,v}\{x, y, v\}.

Proof. DD has at least 3 nodes, because its external face has rr, xx, yy and ww, so it is biconnected and its external face is a cycle CC with the nodes in the order r,x,w,yr, x, w, y. The nine paths are: u−xu - x and u−yu - y along CC through rr, which stands for uu; w−xw - x and w−yw - y along CC; w−vw - v by PwP_w; u−vu - v by the tree path from uu up to vv, which is outside T(u)T(u) except at uu; Z−xZ - x by PxP_x and Z−yZ - y by PyP_y; and Z−vZ - v by the tree path. The paths in DD use disjoint parts of CC. PxP_x, PyP_y and PwP_w leave DD through different subtrees or single edges and end below vv, at vv, or at ancestors of vv. The two tree paths use ancestors of uu that are at least vv, and ancestors of vv below it, which are not in T(u)T(u). So the paths are internally disjoint. □\square

Minor B. In case 2, if ww has a pertinent child component that is also externally active, then GG contains a subdivision of K3,3K_{3,3} with parts {v,w,Z}\{v, w, Z\} and {x,y,W}\{x, y, W\}, where WW is a vertex in that child's subtree.

Proof. Let ss be the child of ww with the pertinent, externally active component. In T(s)T(s) there is a path to vv (pertinence) and a path to an ancestor of vv below vv (external activity, since low(s)<v\mathrm{low}(s) < v). Both start in T(s)T(s), which is connected, so they have a common first part from ww to a vertex WW after which they split. The nine paths are: v−xv - x and v−yv - y along CC, the external face cycle of BB, through rcr_c; w−xw - x and w−yw - y along CC; w−Ww - W in T(s)T(s); W−vW - v and W−ZW - Z; Z−xZ - x by PxP_x; Z−yZ - y by PyP_y. They are internally disjoint for the same reasons as in Minor A. □\square

The x-y path. In case 2 without Minor B, Boyer and Myrvold show that BB has a path PP between a node pxp_x on the external face between rcr_c and xx (with px=xp_x = x allowed) and a node pyp_y between rcr_c and yy, with its inner nodes inside BB, that separates rcr_c from ww in BB. It comes from the boundary of the faces of BB at rcr_c, all of whose nodes were walked in step vv. This is the place where the argument here is a sketch.

Minor C. If px≠xp_x \ne x (or, the same with xx and yy swapped, py≠yp_y \ne y), then GG contains a subdivision of K3,3K_{3,3} with parts {px,w,Z}\{p_x, w, Z\} and {v,x,y}\{v, x, y\}.

Proof. On CC the order is rc,px,x,w,y,pyr_c, p_x, x, w, y, p_y, with pxp_x strictly between rcr_c and xx. The paths are: px−vp_x - v along CC; px−xp_x - x along CC; px−yp_x - y by PP and then along CC from pyp_y to yy; w−xw - x, w−yw - y along CC; w−vw - v by PwP_w; Z−xZ - x, Z−yZ - y by PxP_x, PyP_y; and Z−vZ - v by the tree path. The parts of CC used are disjoint, PP is inside BB, and the other paths are outside BB. □\square

Minors D and E. If px=xp_x = x and py=yp_y = y, Boyer and Myrvold consider a vertex zz inside PP. If there is a path inside BB from zz to the part of CC from xx to yy, it gives a K3,3K_{3,3} (Minor D). Otherwise they use the external activity of the vertices on the lower part of CC and of ww: if ww is also externally active the result is a K5K_5, and in the remaining subcases a K3,3K_{3,3} (Minor E and its variants). These cases are not reproduced here.

Theorem 2. BM-PLANAR returns a rotation system if and only if GG is planar. If GG is not planar it returns nil, and every graph rejected at line L1 is non-planar by the edge bound.

Proof. If it returns a rotation system, GG is planar by Theorem 1. If GG is planar, line L1 does not reject it, and line L7 never fails because a failure gives a Kuratowski subgraph by Lemma 3 and the minors. ■\blacksquare

Back to Boyer-Myrvold planarity test