Journal of Graph Algorithms and Applications Drawing Arrangement Graphs in Small Grids, or How to Play Planarity

We describe a linear-time algorithm that finds a planar drawing of every graph of a simple line or pseudoline arrangement within a grid of area O(n 7/6). No known input causes our algorithm to use area Ω(n 1+) for any > 0; finding such an input would represent significant progress on the famous k-set problem from discrete geometry. Drawing line arrangement graphs is the main task in the Planarity puzzle.


Introduction
Planarity (http://planarity.net/) is a puzzle developed by John Tantalo and Mary Radcliffe in which the user moves the vertices of a planar graph, starting from a tangled circular layout (Figure 1), into a position where its edges (drawn as straight line segments) do not have any crossings. The game is played in a sequence of levels, of increasing difficulty. To construct the graph for the ith level of the game, the game applet chooses = i + 3 random lines in general position in the plane. It creates a vertex for each of the ( − 1)/2 crossings of two lines in this arrangement, and an edge for each of the ( − 2) pairs of crossings that are consecutive on the same line. One strategy for solving Planarity would be to reconstruct a set of lines forming the given graph (Figure 2, left). However, this is tedious to do by hand, and has high computational complexity: testing whether an arrangement of curves can be stretched to form a combinatorially equivalent line arrangement is NPhard [21], from which it follows that recognizing the graphs of line arrangements is also NP-hard [4]. More precisely, both problems are complete for the existential theory of the reals [18]. And although drawings constructed in this way accurately convey the underlying construction of the graph, they have low angular resolution (at most π/ ) and close vertex spacing, making them hard to read and hard to place accurately by hand. Instead, in practice these puzzles may be solved more easily by an incremental embedding strategy that maintains a planar embedding of a subgraph of the input, starting from a single short cycle (such as a triangle or quadrilateral), and that at each step extends the embedding by a single face, bounded by a short path connecting two vertices on the boundary of the previous embedding. When using this strategy to solve a Planarity puzzle, the planar embedding may be kept tidy by placing each vertex into an approximate grid (Figure 2, right). Curiously, the grid drawings found by this incremental grid-placement heuristic appear to have near-linear area; in contrast, there exist planar graphs such as the nested triangles graph that cannot be drawn planarly in a grid of less than Θ(n 2 ) area [7,25].
In this paper we explain this empirical finding of small grid area by developing an efficient algorithm for constructing compact grid drawings of the arrangement graphs arising in Planarity. Because recognizing line arrangement graphs is NP-hard, we identify a larger family of planar graphs (the graphs of simple pseudoline arrangements) that may be recognized and decomposed into their constituent pseudolines in linear time. We show that every n-vertex simple pseudoline arrangement graph may be drawn in linear time in a grid of size ; here κ max ( ) is the maximum complexity of a k-level of a pseudoline arrangement with pseudolines [16,20,23], a topological variant of the famous k-set problem from discrete geometry (see Section 3 for a formal definition). The best proven upper bounds of O( 4/3 ) on the complexity of klevels [6,20,23] imply that the grid in which our algorithm draws these graphs has size O(n 2/3 ) × O( √ n) and area O(n 7/6 ). However, all known lower bounds on k-level complexity are of the form O( 1+ ) for all > 0 [16,24], suggesting that our algorithm is likely to perform even better in practice than our worstcase bound. If we could find a constant > 0 and a family of inputs that would cause our algorithm to use area Ω( 1+ ), such a result would represent significant progress on the k-set problem.
We also investigate the problem of constructing universal point sets for arrangement graphs, sets of points that can be used as the vertices for a straightline planar drawing of every n-vertex arrangement graph. Our construction di-rectly provides a universal point set consisting of O(n 7/6 ) grid points; we show how to sparsify this structure, leading to the construction of a universal set of O(n log n) points in the form of a subset of a grid whose dimensions are again . Finally, we formalize and justify an algorithm for manual solution of these puzzles that greedily finds short cycles and adds them as faces to a partial planar embedding. Although this algorithm may fail for general planar graphs, we show that for arrangement graphs it always finds a planar embedding that is combinatorially equivalent to the original arrangement. Following Shor [21], we define a pseudoline to be the image of a line under a homeomorphism of the Euclidean plane. Pseudolines include lines, non-self-crossing polygonal chains starting and ending in infinite rays, and the graphs of continuous real functions. A crossing of two pseudolines is a point x such that a neighborhood of x can be mapped homeomorphically to a neighborhood of the crossing point of two lines, with the map taking the pseudolines to the lines within this neighborhood. An arrangement of pseudolines is a finite set of pseudolines, the intersection of every two of which is a single crossing point. An arrangement is simple if all pairs of pseudolines have distinct crossing points. A pseudoline arrangement graph is a planar graph whose vertices correspond to the crossings in a simple pseudoline arrangement, and whose edges connect consecutive crossings on a common pseudoline.

Preliminaries
Most of the ideas in the following result are from Bose et al. [4], but we elaborate on that paper to show that linear time recognition of arrangement graphs is possible. (See [9] for a more complicated linear time algorithm that recognizes the dual graphs of a wider class of arrangement graphs, the graphs of weak pseudoline arrangements in which pairs of pseudolines need not cross) Lemma 1. If we are given as input a graph G, then in linear time we can determine whether it is a pseudoline arrangement graph, determine its (unique) embedding as an arrangement graph, and find a pseudoline arrangement for which it is the arrangement graph.
Proof. Let G * be formed from a pseudoline arrangement graph G by adding a new vertex v ∞ adjacent to all vertices in G of degree less than four. As Bose et al. [4] show, G * is 3-connected and planar, and its unique planar embedding is compatible with the embedding of G as an arrangement graph. For convenience we include two edges in G * from v ∞ to each degree two vertex in G, so that, in G * , all vertices except v ∞ have degree four. With this modification, the pseudolines of the arrangement for G are represented in G * by paths starting and ending at v ∞ that, at each other vertex, connect two opposite edges in the embedding.
For any given graph G of maximum degree four we may, in linear time, add a new vertex v ∞ , test planarity of the augmented graph G * , and embed G * in the plane. The edge partition of G * into paths through opposite edges at each degree four vertex may be found in linear time by connected component analysis. By labeling each edge with the identity of its path, we may verify that this partition does not include cycles disjoint from v ∞ and that no path crosses itself. We additionally check that G has ( −1)/2 vertices, where is the number of paths. Finally, by listing the pairs of paths passing through each vertex and bucket sorting this list, we may verify in linear time that no two paths cross more than once. If G passes all of these checks, its decomposition into paths gives a valid pseudoline arrangement, which may be constructed by viewing the embedding of G * as being on a sphere, puncturing the sphere at point v ∞ , and homeomorphically mapping the punctured sphere to the plane.

Small Grids
To describe our grid drawing algorithm for pseudoline arrangement graphs, we need to introduce the concept of a wiring diagram. A wiring diagram is a particular kind of pseudoline arrangement, in which the pseudolines largely lie on horizontal lines (with coordinates y = 1, y = 2, . . . , y = ). The pseudolines on two adjacent tracks may cross each other, swapping which track they lie on, near points with coordinates x = 1, x = 2, . . . , x = ( − 1)/2; each crossing is formed by removing two short segments of track and replacing them by two crossing line segments between the tracks. It is convenient to require different crossings to have different x coordinates, following Goodman [12], although some later sources omit this requirement. Figure 4 depicts an example. Wiring diagrams already provide reasonably nice grid drawings of arrangement graphs [17], but are unsuitable for our purposes, for two reasons: they draw the edges connecting pairs of adjacent crossings as polygonal chains with two bends, and for some arrangements, even allowing crossings to share x-coordinates, drawing the  wiring diagram of lines in a grid may require width Ω( 2 ) (Figure 5), much larger than our bounds. Instead, we will use these diagrams as a tool for constructing a different and more compact straight-line drawing.
For an arrangement of non-vertical lines in general position, an equivalent wiring diagram may be constructed by a plane sweep algorithm [3], which simulates the left-to-right motion of a vertical line across the arrangement. At most points in the sweep, the intersection points of the arrangement lines with the sweep line maintain a fixed top-to-bottom order with each other, with their positions in this order reflected in the assignment of the corresponding pseudolines to tracks. When the sweep line crosses a vertex of the arrangement, two intersection points swap positions in the top-to-bottom order, corresponding to a crossing in the wiring diagram. The left-to-right order of crossings in the wiring diagram is thus exactly the sorted order of the crossing points of the arrangement, as sorted by their x coordinates. The wiring diagram in Figure 4 was constructed in this way from the approximate line arrangement depicted in Figure 1.
Every simple pseudoline arrangement, also, has an equivalent wiring diagram, that may be constructed in time linear in its number of crossings. The proof of this fact uses topological sweeping, a variant of plane sweeping originally developed to speed up sweeping of straight line arrangements by relaxing the strict left-to-right ordering of the crossing points [8], that can also be extended to apply to pseudoline arrangements [22]. The steps of the topological sweeping algorithm require only determining the relative ordering of crossings along each of the input pseudolines, something that may easily be determined from our path decomposition of a pseudoline arrangement graph by precomputing the position of each crossing on each of the two pseudolines it belongs to.
We define the ith level L D (i) in a wiring diagram D to be the set of crossings that occur between tracks i and i + 1. A crossing belongs to L D (i) if and only if i − 1 lines pass between it and the bottom face of the arrangement (the face below all of the tracks in the wiring diagram); therefore, once this bottom face is determined, the levels are fixed by this choice regardless of how the crossings are ordered to form a wiring diagram. If we define the size |D| of a diagram to be its number of pseudolines, and the level complexity κ(D) to be max i |L D (i)|, then it is a longstanding open problem in discrete geometry (a variant of the k-set problem) to determine the maximum level complexity of an arrangement of pseudolines, κ max ( ) = max |D|= κ(D). The known bounds on this quantity are κ max ( ) = O( 4/3 ) [6,20,23], and κ max ( ) = Ω( c √ log ) for some constant c > 1 [16,24], where the last bound is O(n 1+ ) for all constants > 0. Proof. We find a decomposition of G into pseudoline paths, by the algorithm of Lemma 1, and use topological sweeping to convert this decomposition into a wiring diagram. We place each vertex v of G at the coordinates (i, j), where i is the position of v within its level of the wiring diagram and j is the number of tracks below its level of the wiring diagram.
With this layout, every edge of G either connects consecutive vertices within the same level as each other, or it connects vertices on two consecutive levels.
In the latter case, each edge between two consecutive levels corresponds to a horizontal segment of the wiring diagram that lies on the track between the two levels; the left-to-right ordering of these horizontal segments is the same as the left-to-right ordering of both the lower endpoints and the upper endpoints of these edges. Because of this consistent ordering of endpoints, no two edges between the same two consecutive levels can cross. There can also not be any crossings between edges that do not both lie in the same level or connect the same two consecutive levels. Therefore, the drawing we have constructed is planar. By construction, it has the dimensions given in the theorem.   Figure 4, for the graph of Figure 1. Although the 6 × 5 grid found by this algorithm is not quite as compact as the manually-found 5×5 grid of Figure 2, it is much smaller than standard grid drawings that do not take advantage of the arrangement structure of this graph. A more careful placement of vertices within each row would improve the angular resolution and edge length of the drawing but we have omitted this step in order to make the construction more clear.

Universal Point Sets
A universal point set for the n-vertex graphs in a class C of graphs is a set U n of points in the plane such that every n-vertex graph in C can be drawn with its vertices in U n and with its edges drawn as non-crossing straight line segments [5]. Grids of O(n) × O(n) points form universal sets of quadratic size for the planar graphs [10,19], and despite very recent improvements to the constant factor in this quadratic size bound [2] this remains the best known upper bound. A rectangular grid that is universal must have Ω(n 2 ) points [7,25]; the best known lower bounds for universal point sets that are not required to be grids are only linear [5].
Subquadratic bounds are known on the size of universal point sets for subclasses of the planar graphs including the outerplanar graphs [14], simply-nested planar graphs [1,2], planar 3-trees [11], and graphs of bounded pathwidth [2]; however, these results do not apply to arrangement graphs. The grid drawing technique of Theorem 1 immediately provides a universal point set for arrangement graphs of size O(n 7/6 ); in this section we significantly improve this bound, while only increasing the area of our drawings by a constant factor.
Following Bannister et al. [2], define a sequence of positive integers ξ i for i  Proof. We may partition the n i vertices in the ith row n i into n i / groups of exactly vertices, together with at most one smaller group; then α i is the number of groups. The contribution to α i from the groups of exactly vertices is at most n/ = ( − 1)/2. There is at most one smaller group per row so the contribution from the smaller groups is at most − 1. Thus the total value of the sum is at most 3( − 1)/2. Proof. Let s = 3( − 1)/2. We form our universal point set as a subset of an s × κ max ( ) grid; the area of the grid from which the points are drawn is exactly 3/2 times the area of the ( − 1)-row grid drawing technique of Theorem 1. In the ith row of this grid, we include in our universal point set min( ξ i , κ max ( )) of the grid vertices in that row. It does not matter for our construction exactly which points of the row are chosen to make this number of points. By Lemma 2, there is a subsequence β i of the first s rows of sequence ξ, such that the β is termwise greater than or equal to α. This subsequence corresponds to a subsequence (r 1 , r 2 , . . . r −1 ) of the rows of our universal point set, such that row r i has at least min( β i , κ max (ell)) ≥ n i points in it. Mapping the ith row of the drawing of Theorem 1 to row r i of this point set will not create any crossings, because the mapping is monotonic within each row and because all edges of the drawing connect pairs of vertices that are either in the same row or in consecutive rows.
The number of points in the point set is O( s log s) where s = α i = O( ). Therefore, this number of points is O( 2 log ) = O(n log n).

Greedy embedding algorithm
The algorithm of Lemma 1 uses as a subroutine a linear-time planarity testing algorithm. Although such algorithms may be efficiently implemented on computers, they are not really suitable for hand solution of Planarity puzzles. Instead, it is more effective in practice to build up a planar embedding one face at a time, by repeatedly finding a short cycle in the input graph and attaching it to the previously constructed partial embedding. Here "short" means as short as can be found; it is not possible to limit attention to cycles of length three, four, or any fixed bound. For instance in Figure 3 the central triangle is separated from the rest of the graph by faces with five sides, and by modifying this example it is possible to separate part of an arrangement graph from the rest of the graph by faces with arbitrarily many sides. Thus, this hand-solution heuristic may be formalized by the following steps.
1. Choose an arbitrary starting vertex v. 2. Find a cycle C 1 of minimum possible length containing v.
3. Embed C 1 as a simple cycle in the plane. 4. While some of the edges of the input graph have not yet been embedded: (a) Let C i be the cycle bounding the current partial embedding. Define an attachment vertex of C i to be a vertex that is incident with edges not already part of the current embedding. (b) Choose two attachment vertices u and v, and a path P i in C i from u to v, such that there are no attachment vertices interior to P i . (c) Find a shortest path S i from u to v, using only edges that are not already part of the current partial embedding. (d) If necessary, adjust the positions of the embedded vertices (without changing the combinatorial structure of the embedding) so that S i may be drawn with straight line edges. (e) Add S i to the embedding, outside C i , so that the new face between P i and S i does not contain C i . After this change, the new bounding cycle C i+1 of the partial embedding is formed from C i by replacing P i by S i .
When it is successful, this algorithm decomposes the input graph into the cycle C 1 and a sequence of edge-disjoint paths S 1 , S 2 , etc. Such a decomposition is known as an open ear decomposition [15].
This greedy ear decomposition algorithm does not always work for arbitrary planar graphs: even the initial cycle that is found by the algorithm may not be a face of an embedding of the given graph, causing the algorithm to make incorrect assumptions about the structure of the embedding. However (ignoring the possible difficulty of performing step d) the algorithm does always correctly embed the arrangement graphs used by Planarity. These graphs may have multiple embeddings; to distinguish among them, define the canonical embedding of an arrangement graph to be the one given by the arrangement from which it was constructed. By Lemma 1, the canonical embedding is unique. As we prove below, the cycles of an arrangement graph that the algorithm assumes to be faces really are faces of the canonical embedding.

Lemma 4.
Let v be an arbitrary vertex of arrangement graph G, and C be a shortest cycle containing v. Then C is a face of the canonical embedding of G.
Proof. Let C be an arbitrary simple cycle through v. Then if C is not a face of the arrangement forming G, there is a line that crosses it; let u and w be two vertices on the boundary of C connected through the interior of C by (Figure 7). Then C together with the path along from u to w form a theta-graph, a graph with two degree three vertices (u and w) connected by three paths. Every vertex of between u and w is caused by a crossing of with another line that also must cross the other two paths of the theta-graph; in addition, each of these two paths must bend at least once at a vertex that does not correspond to a line that crosses . Therefore, the path through is strictly shorter than the other two paths in the theta-graph. Replacing one of the two paths of C from u to w by the path through produces a shorter cycle that still contains v. Since an arbitrary cycle C that is not a face can be replaced by a shorter cycle through v, it follows that every shortest cycle through v is a face.
Lemma 5. Let D be a drawing of a subset of the faces of the canonical embedding of an arrangement graph G whose union is a topological disk, let u and v be two attachment vertices on the boundary of D with no attachment vertices interior to the boundary path P from u to v, and let S be a shortest path from u to v using only edges not already part of D. Then the cycle formed by the union of P and S is a face of the canonical embedding of G.
Proof. Assume for a contradiction that P ∪ S is not a face; then as in the proof of Lemma 4, this cycle must be crossed by a line , a path L of which forms a theta-graph together with P ∪ S. Additionally, because P is assumed to be part of a drawing of a subset of the faces of G, it cannot be crossed by , for any crossing would cause it to have an attachment vertex between u and v. Therefore, the two degree-three vertices of the theta-graph both belong to S. By the same reasoning as in the proof of Lemma 4, L must be strictly shorter than the other two paths of the theta-graph, so replacing the path that is entirely within S by L would produce a shorter path from u to v, contradicting the construction of S as a shortest path. This contradiction shows that P ∪ S must be a face, as the lemma states.
Theorem 3. When the greedy ear decomposition embedding algorithm described above is applied to an arrangement graph G, it correctly constructs the canonical embedding of G.
Proof. We use induction on the number of steps of the algorithm, with an induction hypothesis that after each step the partial embedding found so far consists of faces of the canonical embedding whose union is a disk. Lemma 4 shows as a base case that the induction hypothesis is true after the first step. In each subsequent step, the ability to find two attachment vertices follows from the fact that arrangement graphs are 2-vertex-connected, which in turn follows from the fact that they can be augmented by a single vertex to be 3-vertex-connected [4]. Lemma 5 shows that, if the induction hypothesis is true after i steps then it remains true after i + 1 steps.

Conclusions
We have found a grid drawing algorithm for pseudoline arrangement graphs that uses area within a small factor of linear, much smaller than the known quadratic grid area lower bounds for arbitrary planar graphs. We have also shown that these graphs have near-linear universal point sets within a constant factor of the same area, and that a simple greedy embedding heuristic suitable for hand solution of Planarity puzzles is guaranteed to find a correct embedding.
The precise area used by our grid drawing algorithm depends on the worstcase behavior of the function κ(D) counting the number of crossings in a k-level of an arrangement; closing the gap between the upper and lower bounds for this function remains an important and difficult open problem in combinatorial geometry. However, closing this gap is not the only possible method for improving our drawing algorithm. A tempting avenue for improvement is to observe that a single pseudoline arrangement may be represented by many different wiring diagrams; therefore, we can select the wiring diagram D that represent the same pseudoline arrangement and that minimizes κ(D). However, this would not improve our worst case width by more than a constant factor. For, if the input forms a pseudoline arrangement constructed by stacking two arrangements of /2 lines with maximal k-level complexity, one above the other (Figure 8), then one of these two instances will survive intact in any wiring diagram for the arrangement, forcing our algorithm to produce a drawing with width at least κ max ( /2). Further improvements in our algorithm will likely come by finding an alternative layout that avoids the complexity of k-levels, by proving that k-levels are small in the average case if not the worst case, or by reducing the known combinatorial bounds on k-levels.