Algorithm Search⌘K

Proofs: Finding faces of a planar graph

These are the human proofs of Finding faces of a planar graph, at full length.

Face tracing outputs each cycle of the face permutation exactly once full

This proof shows: correctness, termination.

Let G=(V,E)G = (V, E) be a simple undirected graph with a rotation system ρ\rho, and let D={(u,v),(v,u):uv∈E}D = \{(u, v), (v, u) : uv \in E\} be its set of 2m2m darts. For a vertex bb of degree k≥1k \ge 1 write ρb=(ρb[0],…,ρb[k−1])\rho_b = (\rho_b[0], \ldots, \rho_b[k-1]), read cyclically, and let pos[(b,a)][(b, a)] be the index of aa in ρb\rho_b. Define

φ(a,b)=(b,ρb[(pos[(b,a)]−1) mod k]),\varphi(a, b) = \big(b, \rho_b[(\text{pos}[(b, a)] - 1) \bmod k]\big),

which is exactly the dart computed by lines L8 and L9.

Lemma 1 (φ\varphi is a permutation of DD). Define ψ(b,w)=(a,b)\psi(b, w) = (a, b) with a=ρb[(pos[(b,w)]+1) mod k]a = \rho_b[(\text{pos}[(b, w)] + 1) \bmod k]. Both maps send darts to darts: φ(a,b)\varphi(a, b) is a dart because ρb[j]\rho_b[j] is a neighbour of bb for each jj. For each dart (a,b)(a, b), ψ(φ(a,b))=(a,b)\psi(\varphi(a, b)) = (a, b), because the index of φ(a,b)\varphi(a,b)'s head in ρb\rho_b is pos[(b,a)]−1[(b, a)] - 1, and adding 1 gives back aa. Likewise φ(ψ(b,w))=(b,w)\varphi(\psi(b, w)) = (b, w). So φ\varphi is a bijection of the finite set DD. □\square

Hence DD is the disjoint union of the cycles of φ\varphi: for each d∈Dd \in D there is a least k≥1k \ge 1 with φk(d)=d\varphi^k(d) = d, and the cycle of dd is C(d)={d,φ(d),…,φk−1(d)}C(d) = \{d, \varphi(d), \ldots, \varphi^{k-1}(d)\}, with kk distinct elements.

Lemma 2 (one walk is one whole cycle). Suppose that at line L5 the start dart d0d_0 is not visited, and that every visited dart lies in a cycle that is disjoint from C(d0)C(d_0). Then the loop of lines L6 to L9 visits exactly the darts d0,φ(d0),…,φk−1(d0)d_0, \varphi(d_0), \ldots, \varphi^{k-1}(d_0) in this order, appends their tails to WW, and stops.

Proof. Invariant at the test of line L6, after jj iterations with 0≤j≤k0 \le j \le k: d=φj(d0)d = \varphi^{j}(d_0), the darts φ0(d0),…,φj−1(d0)\varphi^0(d_0), \ldots, \varphi^{j-1}(d_0) are visited and are the last jj darts marked, and WW holds their tails in order. It holds for j=0j = 0. If j<kj < k, then φj(d0)\varphi^{j}(d_0) is in C(d0)C(d_0) and differs from the jj darts of the cycle visited so far, and it was not visited before the walk by the hypothesis. So the test succeeds, line L7 marks it and appends its tail, and line L9 sets d=φj+1(d0)d = \varphi^{j+1}(d_0). If j=kj = k, then d=φk(d0)=d0d = \varphi^k(d_0) = d_0, which line L7 marked in the first iteration, so the loop stops. □\square

Theorem (correctness and termination). FACES(ρ)(\rho) stops after exactly 2m2m iterations of line L7, and the list FF it returns contains each cycle of φ\varphi exactly once, as the sequence of tails of its darts in the order of φ\varphi.

Proof. We show by induction over the iterations of the loop of line L3 that, at the start of each iteration, the visited set is the union of the cycles already appended to FF, and that these cycles are distinct.

At the start, both are empty. Consider the iteration for the dart (u,v)(u, v). If (u,v)(u, v) is visited, line L4 skips it and nothing changes. If not, then by the induction hypothesis the visited darts form whole cycles that do not contain (u,v)(u, v); since cycles are disjoint, none of them meets C((u,v))C((u, v)). Lemma 2 applies: the walk appends exactly C((u,v))C((u, v)), a cycle not yet in FF, and the visited set becomes the union of the old cycles and this one. So the statement holds after the iteration.

Each dart of DD is taken once by line L3. At the end, every dart was either visited before its turn or started a walk, so every dart is visited, and the visited set, which is the union of the cycles in FF, is all of DD. Since the cycles in FF are distinct and cover DD, FF contains each cycle exactly once. Line L7 marks each dart once, so it runs exactly 2m2m times, and line L3 runs 2m2m times; the algorithm stops. □\square

Faces of a drawing. Suppose now that ρ\rho is read from a straight-line planar drawing, with ρv\rho_v in counterclockwise order. Fix a vertex bb and a disc BB around pbp_b so small that it meets only the segments at bb and no other vertex. The segments at bb cut BB into deg⁡b\deg b open sectors, one between each pair of rays that are consecutive in ρb\rho_b, and each sector lies in one face. Let a walk arrive at bb along the dart (a,b)(a, b). Put pbp_b at the origin with the ray to aa pointing in the direction of angle 0. Walking from pap_a toward pbp_b moves in the direction of angle π\pi, and its left side is the side of angles just below 00, which is the sector between the ray to aa and the next ray clockwise. That next ray goes to the neighbour ww just before aa in the counterclockwise order ρb\rho_b, so the sector is the one between the rays to ww and to aa. Leaving along (b,w)(b, w), the left side is the side just counterclockwise of the ray to ww, which is the same sector. So the face on the left of (a,b)(a, b) near pbp_b is also on the left of φ(a,b)\varphi(a, b). By induction along a cycle, all darts of one cycle of φ\varphi have the same face on their left. Conversely, each face of a connected plane graph has a boundary that is one closed walk (Mohar and Thomassen, Chapters 3 and 4), so it is the face on the left of exactly one cycle of φ\varphi. Therefore, for a connected drawing, the walks in FF are the face boundaries, one for each face. ■\blacksquare

Back to Finding faces of a planar graph