Algorithm Search⌘K

Proofs: Doubly connected edge list

These are the human proofs of Doubly connected edge list, at full length.

The doubly connected edge list represents a connected plane graph and its faces full

This proof shows: correctness, termination.

We use the pseudocode of the page. A half-edge is live if it has not been freed. For a live half-edge hh, write tgt(h)=origin[twin(h)]\mathrm{tgt}(h) = origin[twin(h)]. For a vertex vv with at least one edge, let σv\sigma_v be the map on the half-edges out of vv given by σv(h)=twin(prev[h])\sigma_v(h) = twin(prev[h]); this is the rotation that line L8 reads. The structure is valid if:

  • (I1) nextnext and prevprev restricted to the live half-edges are permutations, and prev[next[h]]=hprev[next[h]] = h for each live hh.
  • (I2) origin[next[h]]=tgt(h)origin[next[h]] = \mathrm{tgt}(h) for each live hh.
  • (I3) face[h]=face[h′]face[h] = face[h'] exactly when hh and h′h' lie on the same cycle of nextnext, and face_edge[f]face\_edge[f] lies on the cycle with label ff, for each face ff that exists.
  • (I4) vertex_edge[v]vertex\_edge[v] is a live half-edge with origin vv, or nil if vv has no edge.
  • (I5) The graph is connected, and there is a drawing of it in the plane whose rotation at each vertex vv (the counterclockwise order of its edges) is σv\sigma_v and whose faces are, one for one, the cycles of nextnext, the face of a cycle being the face that lies to the left of its half-edges.

Lemma 1 (face tracing). Let rotrot be a rotation system of a graph, and let ϕ\phi map the dart (u,v)(u, v) to (v,w)(v, w), where ww is the neighbour just before uu in rot[v]rot[v]. Then ϕ\phi is a permutation of the darts, and the inverse sends (v,w)(v, w) to (u,v)(u, v) where uu is the neighbour just after ww in rot[v]rot[v]. If rotrot is the rotation system of a drawing of a connected plane graph, the cycles of ϕ\phi are exactly the boundary walks of the faces, each traversed with its face on the left.

Proof. Given (v,w)(v, w), the dart (u,v)(u, v) with ϕ(u,v)=(v,w)\phi(u, v) = (v, w) must have ww just before uu in rot[v]rot[v], so uu is the unique neighbour just after ww. So ϕ\phi is one-to-one on a finite set, hence a permutation. The second part is the face tracing theorem for rotation systems (Mohar and Thomassen, Chapter 3; see rotation system). □\square

Lemma 2 (BUILD). If rotrot is the rotation system of a drawing of a connected plane graph with nn vertices and mm edges, BUILD stops after O(n+m)O(n + m) dictionary operations and returns a valid structure.

Proof. Lines L1 and L2 create one pair of half-edges for each edge, since a pair is created only when (u,v)(u, v) has none, and each edge uvuv appears as v∈rot[u]v \in rot[u]. Line L4 sets next[h]=ϕ(h)next[h] = \phi(h) and prev[ϕ(h)]=hprev[\phi(h)] = h, so (I1) holds by Lemma 1, and (I2) holds since ϕ(u,v)\phi(u, v) starts at vv. Lines L5 and L6 label each cycle of nextnext: the walk of line L6 stops when it reaches hh again, which it does because nextnext is a permutation, and each step labels one half-edge that had no label, so the number of unlabeled half-edges drops by 1 at each step and lines L5 and L6 take 2m2m steps in all. This gives (I3). The code sets vertex_edge[u]vertex\_edge[u] to a half-edge out of uu, so (I4) holds. For (I5), take the drawing of rotrot. For a half-edge h=(v,u)h = (v, u), prev[h]=ϕ−1(h)=(x,v)prev[h] = \phi^{-1}(h) = (x, v) where xx is just after uu in rot[v]rot[v] by Lemma 1, so σv(h)=(v,x)\sigma_v(h) = (v, x) is the next half-edge out of vv counterclockwise, and σv\sigma_v is the rotation of the drawing. The faces are the cycles of next=ϕnext = \phi by Lemma 1. □\square

Lemma 3 (walks). In a valid structure, NEIGHBOURS(vv) outputs the neighbours of vv in counterclockwise order, each once, and stops after deg⁡(v)\deg(v) steps; FACE-BOUNDARY(ff) outputs the cycle of ff and stops after ∣f∣|f| steps.

Proof. By (I5), σv\sigma_v is a cyclic order of the deg⁡(v)\deg(v) half-edges out of vv, one cycle of length deg⁡(v)\deg(v). Line L8 applies σv\sigma_v from vertex_edge[v]vertex\_edge[v], which starts at vv by (I4), and stops on its return, so it lists each half-edge out of vv once, and their targets in counterclockwise order. Line L9 follows nextnext from face_edge[f]face\_edge[f], which lies on the cycle of ff by (I3), and stops on its return, after one round of that cycle. □\square

Lemma 4 (SPLIT-FACE). Let the structure be valid, a≠ba \ne b with face[a]=face[b]=fface[a] = face[b] = f, u=origin[a]≠v=origin[b]u = origin[a] \ne v = origin[b], and u,vu, v not adjacent. After SPLIT-FACE(aa, bb), the structure is valid, with one more edge and one more face.

Proof. Let the cycle of ff be a=c0,c1,…,ck=prev[b],ck+1=b,…,cr=prev[a]a = c_0, c_1, \ldots, c_k = prev[b], c_{k+1} = b, \ldots, c_r = prev[a], so 0≤k<r0 \le k < r and bb follows ckc_k. Line L11 changes nextnext only at prev[a]prev[a], prev[b]prev[b], hh and tt, and sets next[cr]=hnext[c_r] = h, next[h]=bnext[h] = b, next[ck]=tnext[c_k] = t, next[t]=anext[t] = a. So the new cycles through these half-edges are h,ck+1,…,crh, c_{k+1}, \ldots, c_r and t,c0,…,ckt, c_0, \ldots, c_k. They partition the old cycle plus hh and tt, and all other cycles are unchanged. Line L11 sets prevprev at the same four places, so (I1) holds. For (I2): origin[b]=v=tgt(h)origin[b] = v = \mathrm{tgt}(h), origin[a]=u=tgt(t)origin[a] = u = \mathrm{tgt}(t), origin[h]=u=tgt(cr)origin[h] = u = \mathrm{tgt}(c_r) because next[cr]next[c_r] was aa, and origin[t]=v=tgt(ck)origin[t] = v = \mathrm{tgt}(c_k) because next[ck]next[c_k] was bb. Line L12 gives the cycle of hh the new label gg and tt the label ff; the other half-edges of the cycle of tt keep ff, so (I3) holds. Vertex records are unchanged, so (I4) holds.

For (I5): by (I5) before the split, the face FF of the drawing that belongs to the cycle of ff has both uu and vv on its boundary. Since FF is an open connected set, there is a simple arc from uu to vv through FF that leaves uu in the angle of FF between the edge of crc_r and the edge of aa, and enters vv in the angle between the edge of ckc_k and the edge of bb. Add it as the new edge. The value σu(y)=twin(prev[y])\sigma_u(y) = twin(prev[y]) changes only for half-edges yy out of uu whose prevprev changed. These are aa, with prev[a]=tprev[a] = t and so σu(a)=h\sigma_u(a) = h, and the new hh, with prev[h]=crprev[h] = c_r and so σu(h)=twin(cr)\sigma_u(h) = twin(c_r), the old value of σu(a)\sigma_u(a). So the new rotation at uu is the old one with hh inserted right after aa, in the angle between aa and twin(cr)twin(c_r), which is the corner of FF where the arc leaves uu. In the same way, σv(b)=twin(h)=t\sigma_v(b) = twin(h) = t and σv(t)=twin(ck)\sigma_v(t) = twin(c_k), so tt is inserted right after bb at vv. So the new drawing has rotation σ\sigma. The arc splits FF into two faces, by the Jordan curve theorem applied to the closed curve made of the arc and a boundary path of FF from vv back to uu, and the faces to the left of hh and of tt are bounded by the two new cycles. All other faces are unchanged. The graph stays connected. □\square

Lemma 5 (ADD-LEAF). In a valid structure, after ADD-LEAF(aa) the structure is valid, with one more vertex, one more edge and the same number of faces.

Proof. Let p=prev[a]p = prev[a]. Line L13 sets next[p]=hnext[p] = h, next[h]=tnext[h] = t, next[t]=anext[t] = a, so the cycle of aa gains h,th, t between pp and aa and no other cycle changes; (I1) holds. (I2): origin[h]=origin[a]=tgt(p)origin[h] = origin[a] = \mathrm{tgt}(p), origin[t]=w=tgt(h)origin[t] = w = \mathrm{tgt}(h), origin[a]=tgt(t)origin[a] = \mathrm{tgt}(t). Both new half-edges get the face of aa, so (I3) holds, and the code sets vertex_edgevertex\_edge of origin[a]origin[a] to hh and of ww to tt, so (I4) holds. In the drawing, put ww in the face of aa near origin[a]origin[a] and join them by a short arc in the angle between the edge of pp and the edge of aa; as in Lemma 4, the rotation at origin[a]origin[a] gains hh next to aa, the rotation at ww is the single half-edge tt, and the face keeps one boundary walk, now with h,th, t in it. The empty case (aa nil, one vertex and no edge) makes the cycle h,th, t, the drawing of one edge, with one face. □\square

Lemma 6 (JOIN-FACES). Let the structure be valid and face[h]≠face[t]face[h] \ne face[t] for t=twin(h)t = twin(h). After JOIN-FACES(hh), the structure is valid, with one edge and one face fewer.

Proof. The cycles of hh and tt are different, so neither next[h]next[h] nor prev[h]prev[h] is tt or hh, and the same for tt. Write the cycles as h,x1,…,xph, x_1, \ldots, x_p and t,y1,…,yqt, y_1, \ldots, y_q with p,q≥1p, q \ge 1, where x1=next[h]x_1 = next[h], xp=prev[h]x_p = prev[h], and likewise for yy. Line L15 sets next[xp]=y1next[x_p] = y_1 and next[yq]=x1next[y_q] = x_1, so the two cycles become the one cycle x1,…,xp,y1,…,yqx_1, \ldots, x_p, y_1, \ldots, y_q, and (I1) holds on the live half-edges. (I2): tgt(xp)=origin[h]=tgt(t)=origin[y1]\mathrm{tgt}(x_p) = origin[h] = \mathrm{tgt}(t) = origin[y_1] and tgt(yq)=origin[t]=origin[x1]\mathrm{tgt}(y_q) = origin[t] = origin[x_1]. Line L14 gives all of x1,…,xpx_1, \ldots, x_p the label of tt, and face_edgeface\_edge of that face becomes y1y_1, so (I3) holds. If vertex_edge[origin[h]]=hvertex\_edge[origin[h]] = h, it becomes twin(xp)twin(x_p), which starts at origin[h]origin[h] and is live because xp≠tx_p \ne t; the same for tt, so (I4) holds.

For (I5), erase the edge of hh from the drawing. Its two sides are the faces of the two cycles, which are different, so the open arc of the edge joins two different faces into one, and the boundary walk of the union is the merged cycle. The rotation at u=origin[h]u = origin[h] loses hh. Before the deletion, σu(y1)=twin(prev[y1])=twin(t)=h\sigma_u(y_1) = twin(prev[y_1]) = twin(t) = h and σu(h)=twin(xp)\sigma_u(h) = twin(x_p). After it, prev[y1]=xpprev[y_1] = x_p, so σu(y1)=twin(xp)\sigma_u(y_1) = twin(x_p), and hh is cut out of the cycle of σu\sigma_u. In the same way, σ(x1)\sigma(x_1) changes from tt to twin(yq)twin(y_q) at origin[t]origin[t], so tt is cut out there. These are the rotations of the drawing without the edge. It remains to see that the graph stays connected. Let GG have nn vertices, mm edges and ff faces, so n−m+f=2n - m + f = 2. The drawing of G−eG - e has m−1m - 1 edges and f−1f - 1 faces, and if it has cc components, Euler's formula for several components gives n−(m−1)+(f−1)=1+cn - (m - 1) + (f - 1) = 1 + c, so c=1c = 1. □\square

Theorem. Starting from BUILD on the rotation system of a connected plane graph, or from the empty structure with one vertex, every sequence of operations whose preconditions hold keeps the structure valid, every walk outputs what its specification says, and every operation terminates. In particular n−m+f=2n - m + f = 2 after each operation.

Proof. The empty structure (one vertex, no half-edge, one face with no half-edge) is valid. By Lemmas 2, 4, 5 and 6, each operation keeps validity, and by Lemma 3 the walks are correct. Each loop walks along a cycle of a permutation of a finite set and stops at its start, so each loop runs at most once around that cycle. Euler's formula holds for the drawing of (I5), and its faces are the cycles of nextnext by (I5). ■\blacksquare

Back to Doubly connected edge list