Algorithm Search⌘K

Proofs: Schnyder drawing algorithm

These are the human proofs of Schnyder drawing algorithm, at full length.

Schnyder's algorithm draws every planar graph without crossings on the (n-2) by (n-2) grid full

This proof shows: correctness, termination.

Let ρ\rho be a planar rotation system of a simple graph GG with n≥3n \ge 3 vertices. We show that SCHNYDER-DRAWING stops and returns integer points in {0,…,n−2}2\{0, \ldots, n - 2\}^2 that give a planar straight-line drawing of GG. Indices of colours are taken mod 3. A plane graph is a graph with a fixed planar rotation system; we use the Jordan curve theorem for the cycles of a plane graph.

Step 1 (line L1 gives a plane triangulation that contains GG). Each new edge is drawn inside one face, between two corners of that face, so the graph stays plane, and the old edges keep their cyclic order. Joining two components at any corners merges one face of each into one face. In the second phase, the new edge abab sits in the corner of vv between vava and vbvb. Here a≠ba \ne b, and abab is not an edge: otherwise v,a,bv, a, b is a cycle and vava, vbvb lie in the same biconnected component, and the union-find structure merges components exactly along such new cycles. After the pass, at every vertex any two consecutive edges, hence all edges, lie in one component, so no vertex is a cut vertex, and GG is 2-connected. In a 2-connected plane graph with at least 3 vertices every face is bounded by a cycle (Diestel, Section 4.2). In the third phase, a face cycle v0,…,vk−1v_0, \ldots, v_{k-1} with k≥4k \ge 4 cannot have both v0v2v_0 v_2 and v1v3v_1 v_3 as edges: both would lie outside the face, inside the disc bounded by the face cycle on the other side, with interleaved ends, and they would cross. So L1 adds a new edge each time, splits off a triangle, and stops with every face a triangle on three distinct vertices: a simple plane triangulation.

Step 2 (line L3 never gets stuck). Let C=c1c2⋯crC = c_1 c_2 \cdots c_r with c1=a1c_1 = a_1, cr=a2c_r = a_2 be the current path and G′G' the graph not yet removed. Invariant: CC plus the edge a2a1a_2 a_1 is a cycle bounding the outer face of G′G', and every other face of G′G' is a triangle. This holds at the start, with C=a1,a3,a2C = a_1, a_3, a_2. Suppose r≥3r \ge 3. If no chord other than a1a2a_1 a_2 exists, every cjc_j with 1<j<r1 < j < r is chord-free. Otherwise, take a chord csctc_s c_t other than a1a2a_1 a_2 with t−s≥2t - s \ge 2 least. A chord from cjc_j, s<j<ts < j < t, to some clc_l would be shorter if s≤l≤ts \le l \le t, and would cross csctc_s c_t inside the disc bounded by the cycle if l<sl < s or l>tl > t. So cs+1c_{s+1} is chord-free. Let z=cjz = c_j be chord-free. Since the faces around zz are triangles, its neighbours in G′G', counterclockwise from p=cj−1p = c_{j-1} to q=cj+1q = c_{j+1}, form a path p,m1,…,mk,qp, m_1, \ldots, m_k, q, and no mm is on CC, because zz has no chord. Removing zz replaces zz on the path by m1,…,mkm_1, \ldots, m_k; the new path is simple, and the invariant holds. The stack holds every chord-free path vertex: a new path vertex is pushed when its count is 0, and an old path vertex loses a chord only in the case k=0k = 0, where it is pushed. So L3 removes n−2n - 2 vertices and ends with the path a1,a2a_1, a_2. Read backwards, the removal order v1=a1v_1 = a_1, v2=a2v_2 = a_2, v3,…,vn=a3v_3, \ldots, v_n = a_3 is a canonical ordering.

Step 3 (two orders). For a vertex vv, let idx⁡(v)\operatorname{idx}(v) be its position in the canonical ordering. Line L4 sets p1(z),p2(z)p_1(z), p_2(z) to vertices removed later, so of smaller index, and p3(m)=zp_3(m) = z for vertices mm removed later than zz, so of larger index. Next, build a list Λ\Lambda of vertices from left to right, going through the canonical order forwards: start with Λ=(a1,a2)\Lambda = (a_1, a_2), and insert each vkv_k immediately before its right lower neighbour qq. Since each vkv_k is inserted between pp and qq, after all vertices between them, pp precedes vkv_k, the vertices mjm_j precede vkv_k, and vkv_k precedes qq. So, writing u→wu \to w for the edge from uu to its parent:

edge idx⁡\operatorname{idx} position in Λ\Lambda
u→p1(u)u \to p_1(u) decreases decreases
u→p2(u)u \to p_2(u) decreases increases
u→p3(u)u \to p_3(u) increases increases

In particular each TiT_i is acyclic, and following parents of colour ii from an inner vertex ends at a vertex with no parent of colour ii. Such a vertex is outer. It is aia_i: every inner edge at a1a_1 is labelled u→a1u \to a_1 of colour 1, since a1a_1 stays the leftmost path vertex and can only be the left neighbour pp; likewise a2a_2 only receives colour 2, and the inner neighbours of a3a_3 are exactly the vertices below a3a_3 at the first step, which receive colour 3. So TiT_i is a tree rooted at aia_i, and Pi(v)P_i(v) is well defined. Every inner edge uvuv, with vv earlier than uu, is labelled exactly once, when uu is removed and vv is one of pp, qq or below uu; the edges a1a2a_1 a_2, a1a3a_1 a_3, a2a3a_2 a_3 get no label.

Lemma 1. For an inner vertex vv, the paths P1(v)P_1(v), P2(v)P_2(v), P3(v)P_3(v) pairwise meet only in vv.

Proof. Along P3(v)P_3(v) the index increases and along P1(v)P_1(v) and P2(v)P_2(v) it decreases, so P3(v)P_3(v) meets the others only at vv. Along P1(v)P_1(v) the position in Λ\Lambda decreases and along P2(v)P_2(v) it increases, so they meet only at vv. □\square

Step 4 (the local rule). Fix an inner vertex v=vkv = v_k. Draw the path at the time vv is added as running from left to right, with the part already built below it. Counterclockwise around vv, starting at pp, come the vertices below vv, then qq, then the neighbours added later, from right to left. A later neighbour zz uses vv as its left neighbour pp while vv is on the path and zz is to the right of vv, as its right neighbour qq when zz is to the left, and as a vertex below zz exactly once, for the vertex zcz_c that removes vv from the path. Each new edge vzvz with zz to the right is inserted in the rotation at vv next to the current edge to the right path neighbour, on the upper side, and similarly on the left. So counterclockwise around vv we see: the outgoing edge of colour 1 (to pp), incoming edges of colour 3 (from the vertices below vv), the outgoing edge of colour 2 (to qq), incoming edges of colour 1 (later neighbours on the right), the outgoing edge of colour 3 (to zcz_c), and incoming edges of colour 2 (later neighbours on the left). This is the rule of a Schnyder wood. Rotating the colour names, at every inner vertex, counterclockwise:

outi−1, ini+1∗, outi, ini−1∗, outi+1, ini∗.(1)\text{out}_{i-1},\ \text{in}_{i+1}^{*},\ \text{out}_i,\ \text{in}_{i-1}^{*},\ \text{out}_{i+1},\ \text{in}_i^{*}. \tag{1}

Step 5 (regions). For an inner vertex vv, the cycle Pi+1(v)∪Pi−1(v)∪ai+1ai−1P_{i+1}(v) \cup P_{i-1}(v) \cup a_{i+1} a_{i-1} is simple by Lemma 1. Let Ri(v)R_i(v) be the closed disc that it bounds inside the outer triangle; we also write Ri(v)R_i(v) for the set of vertices in it. Near vv, the disc is one of the two wedges between outi+1(v)\text{out}_{i+1}(v) and outi−1(v)\text{out}_{i-1}(v). It is the wedge that does not contain outi(v)\text{out}_i(v), because Pi(v)P_i(v) leaves vv through that edge, never meets the cycle again (Lemma 1, and aia_i is not on the cycle), and ends at the outer vertex aia_i, outside the disc. By (1) this wedge contains the incoming edges of colour ii at vv and no incoming edges of colours i±1i \pm 1. Along Pi−1(v)P_{i-1}(v), the disc stays on one side. At a vertex w≠vw \ne v of Pi−1(v)P_{i-1}(v), the path enters through an incoming edge of colour i−1i - 1 and leaves through outi−1(w)\text{out}_{i-1}(w), and by (1) the side of the disc contains ini∗\text{in}_i^{*} and outi+1(w)\text{out}_{i+1}(w), but no incoming edge of colour i+1i + 1, since those lie on the other side, between outi−1(w)\text{out}_{i-1}(w) and outi(w)\text{out}_i(w). Symmetrically, at a vertex w≠vw \ne v of Pi+1(v)P_{i+1}(v), the side of the disc contains ini∗\text{in}_i^{*} and outi−1(w)\text{out}_{i-1}(w), and no incoming edge of colour i−1i - 1. At ai+1a_{i+1} and ai−1a_{i-1} no edge of colour i∓1i \mp 1 enters. We record:

(A) No edge of colour i+1i + 1 enters a vertex of Pi−1(v)P_{i-1}(v) from inside Ri(v)R_i(v), and no edge of colour i−1i - 1 enters a vertex of Pi+1(v)P_{i+1}(v) from inside Ri(v)R_i(v). Every edge of colour ii that enters a boundary vertex comes from inside, and every outgoing edge of colour ii at a boundary vertex points outside.

The three discs R1(v)R_1(v), R2(v)R_2(v), R3(v)R_3(v) cover the outer triangle and overlap only on the three paths, since the three paths cut the triangle into three parts.

Lemma 2. Let vv be inner and u∈Ri(v)u \in R_i(v) an inner vertex, u≠vu \ne v. Then Ri(u)⊆Ri(v)R_i(u) \subseteq R_i(v). If u∉Pi−1(v)u \notin P_{i-1}(v), then Pi+1(u)P_{i+1}(u) does not meet Pi−1(v)P_{i-1}(v); if u∈Pi−1(v)u \in P_{i-1}(v), then Pi+1(u)P_{i+1}(u) meets Pi−1(v)P_{i-1}(v) only in uu.

Proof. Follow Pi+1(u)P_{i+1}(u). It can leave the disc only through a boundary vertex. If it reaches a vertex of Pi+1(v)P_{i+1}(v), it continues along Pi+1(v)P_{i+1}(v), since both follow the parents in Ti+1T_{i+1}, and stays on the boundary. By (A) it cannot enter a vertex of Pi−1(v)P_{i-1}(v) from inside; and if it starts at u∈Pi−1(v)u \in P_{i-1}(v), then outi+1(u)\text{out}_{i+1}(u) points into the disc, as shown in Step 5. So Pi+1(u)P_{i+1}(u) stays in Ri(v)R_i(v) and meets Pi−1(v)P_{i-1}(v) at most in its start. Symmetrically, Pi−1(u)P_{i-1}(u) stays in Ri(v)R_i(v). The cycle bounding Ri(u)R_i(u) therefore lies in the disc Ri(v)R_i(v), and so does the disc it bounds. □\square

Lemma 3. Let vv be inner and u∈Ri(v)u \in R_i(v) an inner vertex, u≠vu \ne v. Then xi(u)≤xi(v)x_i(u) \le x_i(v), with equality only if u∈Pi−1(v)u \in P_{i-1}(v).

Proof. Let R=Ri(v)R = R_i(v) and R′=Ri(u)⊆RR' = R_i(u) \subseteq R. A vertex of Pi−1(v)P_{i-1}(v) that lies in R′R' is on the boundary of RR, hence on the boundary of R′R', so it lies on Pi+1(u)P_{i+1}(u) or Pi−1(u)P_{i-1}(u).

If u∉Pi−1(v)u \notin P_{i-1}(v), let ww be the first vertex of Pi−1(u)P_{i-1}(u) on Pi−1(v)P_{i-1}(v); it exists because both end at ai−1a_{i-1}, and from ww on the two paths coincide. The vertices of Pi−1(v)P_{i-1}(v) before ww are not on Pi−1(u)P_{i-1}(u), and not on Pi+1(u)P_{i+1}(u) by Lemma 2, so they are in R∖R′R \setminus R'. Hence

xi(v)−xi(u)=∣R∖R′∣−(∣Pi−1(v)∣−∣Pi−1(u)∣)≥#{vertices of Pi−1(u) before w}≥1.x_i(v) - x_i(u) = \lvert R \setminus R' \rvert - \big(\lvert P_{i-1}(v) \rvert - \lvert P_{i-1}(u) \rvert\big) \ge \#\{\text{vertices of } P_{i-1}(u) \text{ before } w\} \ge 1.

If u∈Pi−1(v)u \in P_{i-1}(v), then Pi−1(u)P_{i-1}(u) is the part of Pi−1(v)P_{i-1}(v) from uu on, and the vertices before uu are not on Pi+1(u)P_{i+1}(u) by Lemma 2, so they are in R∖R′R \setminus R', and the same computation gives xi(v)−xi(u)≥0x_i(v) - x_i(u) \ge 0. □\square

Step 6 (lines L5 to L7 compute ∣Ri(v)∣|R_i(v)|). Let uu be strictly inside Ri(v)R_i(v). Pi(u)P_i(u) ends at ai∉Ri(v)a_i \notin R_i(v), so it reaches a first boundary vertex xx; xx is inner, since no edge of colour ii enters ai±1a_{i \pm 1}. Conversely, by (A), the children in TiT_i of a boundary vertex lie strictly inside, and a path in TiT_i that touches the boundary leaves the disc through an outgoing edge of colour ii and can never re-enter it, since edges of colour ii enter the boundary only from inside. So the vertices strictly inside Ri(v)R_i(v) are the disjoint union, over the inner vertices xx of Pi+1(v)∪Pi−1(v)P_{i+1}(v) \cup P_{i-1}(v), of the subtrees of xx in TiT_i without xx. Counting vv once,

∣Ri(v)∣=∣Pi+1(v)∣+∣Pi−1(v)∣−1+Σii+1(v)+Σii−1(v)−(Di(v)−1),\lvert R_i(v) \rvert = \lvert P_{i+1}(v) \rvert + \lvert P_{i-1}(v) \rvert - 1 + \Sigma_i^{i+1}(v) + \Sigma_i^{i-1}(v) - (D_i(v) - 1),

which is line L7. Line L6 computes ∣Pj(v)∣=∣Pj(pj(v))∣+1\lvert P_j(v) \rvert = \lvert P_j(p_j(v)) \rvert + 1 and Σji(v)=Σji(pj(v))+Di(v)−1\Sigma_j^i(v) = \Sigma_j^i(p_j(v)) + D_i(v) - 1 from the root of TjT_j down.

Step 7 (coordinates). Every vertex lies in exactly one region, except the vertices of Pj(v)∖{v}P_j(v) \setminus \{v\}, which lie in two, and vv, which lies in three. So

x1(v)+x2(v)+x3(v)=n+∑j(∣Pj(v)∣−1)+2−∑j∣Pj(v)∣=n−1,x_1(v) + x_2(v) + x_3(v) = n + \sum_j (\lvert P_j(v) \rvert - 1) + 2 - \sum_j \lvert P_j(v) \rvert = n - 1,

and the corners of L8 sum to n−1n - 1 too. Since Ri(v)⊇Pi+1(v)∪Pi−1(v)R_i(v) \supseteq P_{i+1}(v) \cup P_{i-1}(v) and ∣Pi+1(v)∣≥2\lvert P_{i+1}(v) \rvert \ge 2, every coordinate of an inner vertex is at least 1, hence at most n−3n - 3. So all output points lie in {0,…,n−2}2\{0, \ldots, n - 2\}^2.

For i∈{1,2,3}i \in \{1, 2, 3\} write u≺ivu \prec_i v if (xi(u),xi+1(u))(x_i(u), x_{i+1}(u)) is lexicographically smaller than (xi(v),xi+1(v))(x_i(v), x_{i+1}(v)). Claim: for every edge uwuw and every vertex v∉{u,w}v \notin \{u, w\}, there is an ii with u≺ivu \prec_i v and w≺ivw \prec_i v.

If v=aiv = a_i, take this ii: every other vertex has xi≤max⁡(1,n−3)<n−2x_i \le \max(1, n - 3) < n - 2 when n≥4n \ge 4; for n=3n = 3 the graph is a triangle and there is nothing to prove. If vv is inner, the edge uwuw does not cross the three paths of vv, so both ends lie in one region Ri(v)R_i(v). Take an end uu. If uu is inner, Lemma 3 gives xi(u)<xi(v)x_i(u) < x_i(v), or xi(u)=xi(v)x_i(u) = x_i(v) and u∈Pi−1(v)∖{v}u \in P_{i-1}(v) \setminus \{v\}. In the second case uu lies on the boundary path P(i+1)+1(v)P_{(i+1)+1}(v) of Ri+1(v)R_{i+1}(v) and, by Lemma 1, not on Pi(v)P_i(v), so Lemma 3 for colour i+1i + 1 gives xi+1(u)<xi+1(v)x_{i+1}(u) < x_{i+1}(v). Either way u≺ivu \prec_i v. If uu is a corner in Ri(v)R_i(v), it is ai+1a_{i+1}, with xi=0<xi(v)x_i = 0 < x_i(v), or ai−1a_{i-1}, with xi=1≤xi(v)x_i = 1 \le x_i(v) and xi+1=0<xi+1(v)x_{i+1} = 0 < x_{i+1}(v). This proves the claim.

Step 8 (no crossings). All points lie in the plane x1+x2+x3=n−1x_1 + x_2 + x_3 = n - 1, and L9 projects it to the first two coordinates by an affine bijection. For a small ε>0\varepsilon > 0, the linear function φi=xi+εxi+1\varphi_i = x_i + \varepsilon x_{i+1} orders the integer points as ≺i\prec_i does. Distinct vertices get distinct points: if x(u)=x(v)x(u) = x(v), pick an edge uwuw with w≠vw \ne v, which exists since every vertex of a triangulation with n≥4n \ge 4 has degree at least 3; the claim gives u≺ivu \prec_i v, a contradiction. A vertex vv does not lie on an edge uwuw with v∉{u,w}v \notin \{u, w\}, because φi(v)>max⁡(φi(u),φi(w))\varphi_i(v) > \max(\varphi_i(u), \varphi_i(w)). Two edges with a common end overlap only if one contains the other end, which was just excluded. Suppose edges uwuw and stst with four distinct ends intersect. By the claim there are ii with φi(s)>φi(u),φi(w)\varphi_i(s) > \varphi_i(u), \varphi_i(w) and jj with φj(t)>φj(u),φj(w)\varphi_j(t) > \varphi_j(u), \varphi_j(w). If i=ji = j, both ss and tt, and the whole segment stst, lie in the open half-plane φi>max⁡(φi(u),φi(w))\varphi_i > \max(\varphi_i(u), \varphi_i(w)), which misses the segment uwuw. So i≠ji \ne j, and likewise there are k≠lk \ne l with uu beating stst in φk\varphi_k and ww in φl\varphi_l. Two 2-element subsets of {1,2,3}\{1, 2, 3\} meet, say i=ki = k. Then φi(s)>φi(u)\varphi_i(s) > \varphi_i(u) and φi(u)>φi(s)\varphi_i(u) > \varphi_i(s), a contradiction. So the drawing of the triangulation is planar, and so is the drawing of its subgraph GG.

Step 9 (orientation). For n≥4n \ge 4 the triangulation is 3-connected, so its planar embeddings are ρ\rho and its mirror image, and the drawing realizes one of them. The corners (n−2,1)(n - 2, 1), (0,n−2)(0, n - 2), (1,0)(1, 0) are in counterclockwise order, since (−(n−2))(−1)−(n−3)(3−n)=(n−2)+(n−3)2>0(-(n - 2))(-1) - (n - 3)(3 - n) = (n - 2) + (n - 3)^2 > 0, and in ρ\rho the outer face lists a1,a2,a3a_1, a_2, a_3 counterclockwise too. So the drawing realizes ρ\rho, not its mirror image, and the edges of GG keep their order. For n=3n = 3 this is immediate.

Termination. Every loop runs over a finite set: L1 adds at most 3n−63n - 6 edges, L3 removes each vertex at most once and pops each pushed vertex once, and L5 to L7 pass over each tree a constant number of times. ■\blacksquare

Back to Schnyder drawing algorithm