Recognizing Stick Graphs with and without Length Constraints

Stick graphs are intersection graphs of horizontal and vertical line segments that all touch a line of slope −1 and lie above this line. De Luca et al. [GD'18] considered the recognition problem of stick graphs when no order is given (STICK), when the order of either one of the two sets is given (STICKA), and when the order of both sets is given (STICKAB). They showed how to solve STICKAB e ciently. In this paper, we improve the running time of their algorithm, and we solve STICKA e ciently. Further, we consider variants of these problems where the lengths of the sticks are given as input. We show that these variants of STICK, STICKA, and STICKAB are all NP-complete. On the positive side, we give an e cient solution for STICKAB with xed stick lengths if there are no isolated vertices. Submitted: November 2019 Reviewed: January 2020 Revised: February 2020 Accepted: March 2020 Final: March 2020 Published: December 2020 Article type: Regular paper Communicated by: D. Archambault and C. D. Tóth A preliminary version of this paper appeared in Proc. Int. Symp. Graph Drawing & Network Visualization 2019 [9]. S.C. and A.W. acknowledge support from DFG grants WO758/11-1 and WO758/9-1, respectively. E-mail addresses: loe er@informatik.uni-wuerzburg.de (Andre Lö er) johannes.zink@uniwuerzburg.de (Johannes Zink) 658 Chaplick et al. Recognizing Stick Graphs


Introduction
For a given collection S of geometric objects, the intersection graph of S has S as its vertex set and an edge whenever S ∩ S = ∅, for S, S ∈ S.This paper concerns recognition problems for classes of intersection graphs of restricted geometric objects, i.e., determining whether a given graph is an intersection graph of a family of restricted sets of geometric objects.An established (general) class of intersection graphs is that of segment graphs, the intersection graphs of line segments in the plane 1 .For example, segment graphs are known to include planar graphs [5].The recognition problem for segment graphs is ∃Rcomplete [19,22] 2 .On the other hand, one of the simplest natural subclasses of segment graphs is that of the permutation graphs, the intersection graphs of line segments where there are two parallel lines such that each line segment has its two end points on these parallel lines 3 .We say that the segments are grounded on these two lines.The recognition problem for permutation graphs can be solved in linear time [20].Bipartite permutation graphs have an even simpler intersection representation [25]: they are the intersection graphs of unit-length vertical and horizontal line segments which are again double-grounded (without loss of generality, both lines have a slope of −1).The simplicity of bipartite permutation graphs leads to a simpler linear-time recognition algorithm [27] than that of permutation graphs.
Several recent articles [2,3,7,8] compare and study the geometric intersection graph classes occurring between the simple classes, such as bipartite permutation graphs, and the general classes, such a segment graphs.Cabello and Jej£i£ [2] mention that studying such classes with constraints on the sizes or lengths of the objects is an interesting direction for future work (and such constraints are the focus of our work).Note that similar length restrictions have been considered for other geometric intersection graphs such as interval graphs [16,17,23].
When the segments are not grounded, but still are only horizontal and vertical, the class is referred to as grid intersection graphs and it also has a rich history, see, e.g., [7,8,14,18].In particular, note that the recognition problem is NP-complete for grid intersection graphs [18].But, if both the permutation of the vertical segments and the permutation of the horizontal segments are given, then the problem becomes a trivial check on the bipartite adjacency matrix [18].However, for the variant where only one such permutation, e.g., the order of the horizontal segments, is given, the complexity remains open.A few special cases of this problem have been solved eciently [6,10,11], e.g., one such case [6] is equivalent to the problem of level planarity testing which can be solved in linear time [15].
In this paper we study recognition problems concerning so-called stick graphs, the intersection graphs of grounded vertical and horizontal line segments (i.e., grounded grid intersection graphs).Classes closely related to stick graphs appear in several application contexts, e.g., in nano PLA-design [26] and detecting loss of heterozygosity events in the human genome [4,13].Note that, similar to the general case of segment graphs, it was recently shown that the recognition problem for grounded segments (where arbitrary slopes are allowed) is ∃Rcomplete [3].So, it seems likely that the recognition problem for stick graphs is NP-complete (similar to grid intersection graphs), but thus far it remains open.The primary prior work on recognizing stick graphs is due to De Luca et al. [10].They introduced two constrained cases of the stick graph recognition problem called STICK A and STICK AB , which we dene next.Similarly to Kratochvíl's approach to grid intersection graphs [18], De Luca et al. characterized stick graphs through their bipartite adjacency matrix and used this result as a basis to develop a polynomial-time algorithm to solve STICK AB .
Denition 1.1 (STICK) Let G be a bipartite graph with vertex set A ∪B, and let be a line with slope −1.Decide whether G has an intersection representation where the vertices in A are vertical line segments whose bottom end-points lie on and the vertices in B are horizontal line segments whose left end-points lie on . 4Such a representation is a stick representation of G, the line is the ground line, the segments are called sticks, and the point where a stick meets is its foot point.
Denition 1.2 (STICK A /STICK AB ) In the problem STICK A (STICK AB ) we are given an instance of the STICK problem and additionally an order σ A (orders σ A , σ B ) of the vertices in A (in A and B).The task is to decide whether there is a stick representation that respects σ A (σ A and σ B ).
Our Contribution.We rst revisit the problems STICK A and STICK AB dened by De Luca et al. [10].We provide the rst ecient algorithm for STICK A and a faster algorithm for STICK AB ; see Section 2. For our STICK A algorithm we introduce a new tool, semi-ordered trees (see Section 2.2), as a way to capture all possible permutations of the horizontal sticks which occur in a solution to the given STICK A instance.We feel that this data structure may be of independent interest.Then we investigate the direction suggested by Cabello and Jej£i£ [2] where specic lengths are given for the segments of each vertex.In particular, this can be thought of as generalizing from unit stick graphs (i.e., bipartite permutation graphs), where every segment has the same length.While bipartite permutation graphs can be recognized in linear time [27], it turns out that all of the new problem variants (which we call STICK fix , STICK fix A , and STICK fix AB ) are NP-complete; see Section 3. Finally, we give an ecient solution for STICK fix AB (that is, STICK AB with xed stick lengths) for the special case that there are no isolated vertices (see Section 3.3).We conclude and state some open problems in Section 4. Our results are summarized in Table 1.Proof: We apply a sweep-line approach (with a vertical sweep-line moving rightwards) where each vertical stick a i ∈ A corresponds to two events: the enter event of a i (abbreviated by i) and the exit event of a i (abbreviated by i ).
Let σ A = (a 1 , . . ., a |A| ) and σ B = (b 1 , . . ., b |B| ).Let β i denote the largest index such that b βi has a neighbor in a 1 , . . ., a i .Let Bi be the subsequence of (b 1 , . . ., b βi ) of those vertices that have a neighbor in a i , . . ., a |A| , and let Bi be the subsequence of (b 1 , . . ., b βi ) of those vertices that have a neighbor in a i+1 , . . ., a |A| .At every event p ∈ {i, i }, we maintain the following invariants.(ii) The x-coordinates of the foot points of {b 1 , . . ., b βi , a 1 , . . ., a i } are unique integers in the range from 1 to β i + i.
We initialize B0 = B0 = ∅ and β 0 = 0. Here, our invariants trivially hold.Now suppose i ≥ 1.In the following, we don't create a new variable Bp for each event p, but we update a single variable B, viewing Bp as the state of B during event p.Consider the enter event of a i .We set the x-coordinate of a i to β i + i.We place the foot points of vertices b βi−1+1 , . . ., b βi (if they exist) between a i−1 and a i in this order and create Bi by appending them to B(i−1) in this order.All neighbors of a i have to start before a i , and they have to be a sux of Bi .If this is not the case, then we simply reject as this is a negative instance of the problem.This is easily checked in O(deg(a i )) time.The upper endpoint of a i is placed 1/2 a unit above the foot point of its rst neighbor in this sux.As such, the invariants (i)(iii) are maintained.
Consider the exit event of a i .For each neighbor b j of a i , we check whether a i is the last neighbor of b j in σ A .In this case, we nish b j and set the x-coordinate of its right endpoint to β i + i + 1/2.Now Bi consists of all vertices in Bi except those that we just nished.This again maintains invariants (i)(iii).Note that processing the exit event always succeeds, i.e., negative instances are detected purely in the enter events.
Hence, if we reach and complete the exit event of a |A| , we obtain a STICK AB representation of G. Otherwise, G has no such representation.Clearly, the whole algorithm runs in O(|A| + |B| + |E|) time.
Note that, even though we have not explicitly discussed isolated vertices, these can be easily realized by sticks of length 1/2.

2.2
Data Structure: Semi-Ordered Trees In the STICK A problem, the goal is to nd a permutation of the horizontal sticks B that is consistent with the xed permutation of the vertical sticks A.
To this end, we will make use of a data structure that allows us to capture many permutations subject to consecutivity constraints.This might remind the reader of other similar but distinct data structures such as PQ-trees [1].
An ordered tree is a rooted tree where the order of the children around each internal is specied.The permutation expressed by an ordered tree T is the permutation of its leaves in the pre-order traversal of T .
Generalizing this, we dene a semi-ordered tree where, for each node, there is a xed permutation for a subset of the children and the remaining children are free.Namely, for each node v, we have Hence, every node (except the root) is ordered or unordered depending on its parent.We obtain an ordered tree from a semi-ordered tree by xing, for each node v, a permutation π v of O v ∪ U v that contains π v as a subsequence.In this way, a permutation π is expressed by a semi-ordered tree S if there exists an ordered tree T that expresses π and can be obtained from S.

2.3
Solving STICK A in O(|A| • |B|) time Let G = (A ∪B, E) and σ A = (a 1 , . . ., a |A| ) be the input.We assume that G is connected and discuss otherwise at the end of this section.
As in the algorithm for STICK AB , we apply a sweep-line approach (with a vertical sweep-line moving rightwards) where each vertical stick a i ∈ A corresponds to two events: the enter event of a i (abbreviated by i) and the exit event of a i (abbreviated by i ).
Overview.Informally, for each event p ∈ {i, i }, we will maintain all rep- resentations of the subgraph seen so far subject to certain horizontal sticks continuing further (those that intersect the sweep-line and some vertical stick before it).We denote by G p the induced subgraph of G containing a 1 , . . ., a i and their neighbors.We distinguish the neighbors as those that are dead (that is, have all neighbors before the sweep-line) and those that are active (that is, have neighbors before and after the sweep-line).Namely, • D i consists of all (dead) sticks of B i with no neighbor in a i , . . ., a |A| ; and • D i consists of all (dead) sticks of B i with no neighbor in a i+1 , . . ., a |A| .
To this end, we maintain an ordered forest T p of special semi-ordered trees that encodes all realizable permutations (dened below) of the set of horizontal sticks B p as the permutations expressed by T p ; see Fig. 2. A permutation π of B p is realizable if there is a stick representation of the graph H p obtained from G p by adding a vertical stick to the right of a i neighboring all horizontal sticks in B p where B p is drawn top-to-bottom in order π.
In the enter event of a i , B i comprises B i−1 and all vertices of B that neighbor a i and aren't in the data structure yet (we call these entering vertices).
We constrain the data structure so that all the neighbors of a i must occur after (below) the non-neighbors of a i .The set D p of dead vertices remains unchanged with respect to the last exit event, that is, In the exit event of a i , D i comprises D i and all sticks of B i that do not have any neighbor a j with j > i, i.e., those having a i as their last neighbor (we call these exiting vertices).No new horizontal sticks appear in an exit event, Data structure.See Fig. 2 for an example.Consider any event p. Observe that G p may consist of several connected components G p 1 , . . ., G p kp .The components of G p are naturally ordered from left to right by σ A .Let B p j denote the vertices of B p in G p j .In this case, in every realizable permutation of B p , the vertices of B p j must come before the vertices of B p j+1 .Furthermore, the vertices that will be introduced any time later can only be placed at the beginning, end, or between the components.Hence, to compactly encode the realizable permutations, it suces to do so for each component G p j individually via a semi-ordered tree T p j .Namely, our data structure will be T p = (T p 1 , . . ., T p kp ).Each data structure T p j is a special semi-ordered tree in which the leaves correspond to the vertices of B p j , all leaves are unordered, and all internal vertices are ordered.
Correctness and event processing.We argue by induction that this data structure is sucient to express the realizable permutations of B p .We maintain the following invariants for each event p during the execution of the algorithm.
(I1) The set of permutations expressed by T p contains all permutations of B p which occur in a stick representation of G.
(I2) The set of permutations expressed by T p contains only permutations of B p which occur in a stick representation of G p .
Since G |A| = G and B |A| = B, after the nal step these invariants ensure that our data structure expresses exactly those permutations of B which occur in a stick representation of G.
Recall that our data structure consists of an ordered set of semi-ordered trees.Note that these invariants also apply to each semi-ordered tree individually, that is, to its corresponding connected component.
In the base case, consider the enter event of a 1 .Our data structure consists of a single component G 1  1 and clearly a single node with a leaf-child for every neighbor of a 1 captures all possible permutations.
In the exit event of a i , we do not change the shape of T i , that is, T i = T i .Then, in T i , we mark the exiting vertices as dead and add them to D i .We  further mark any internal node in T i that contains only dead leaves in its subtree as dead as well.Obviously, this procedure maintains all the invariants.Now consider the enter event of a i and assume that we have the data structure T (i−1) = (T ki−1 ).The essential observation is that the neighbors of a i must form a sux of the active vertices in B (i−1) in every real- izable permutation after the enter event, which we will enforce in the following.Namely, either • all active vertices in B (i−1) are adjacent to a i , • none of them are adjacent to a i , or • there is an s ∈ {1, . . ., k i−1 } such that (i) B Otherwise, there is no realizable permutation for this event and consequently for G.The rst two cases can be seen as degenerate cases (with s = 0 or s = k i−1 + 1) of the general case below.
We rst show how to process T (i−1) s ; see Fig. 3b.Afterwards we will create the data structure T i .We create a tree T that expresses precisely the subset of the permutations expressed by T (i−1) s where all leaves that are neighbors of a i occur as a sux.We initialize T = T Otherwise, we say that a node of T is marked if all active leaves in its subtree are neighbors of a i ; it is unmarked if no active leaf in its subtree is a neighbor of a i ; and it is half-marked otherwise.Note that the root of T is half-marked.
Since the neighbors of a i must form a sux of the active leaves, the marked non-leaf children of a half-marked node form a sux of the active children, the unmarked non-leaf children form a prex of the active children, and there is at most one half-marked child.Hence, the half-marked nodes form a path in T that starts in the root; otherwise, there are no realizable permutations for this event and subsequently for G.
We traverse the path starting from the deepest descendant and ending at the root, i.e., bottom-to-top.Let x be a half-marked node, and let y be its half-marked child (if it exists); see Fig. 3b.We have to enforce that in any ordered tree obtained from T , the unmarked children of x occur before y and the marked children of x occur after y.We create a new marked vertex x .This vertex receives the following children from x: the marked leaf-children and the sux of the non-leaf children starting after y.Symmetrically, we create a new unmarked vertex x , which receives the following children from x: the unmarked leaf-children and the prex of the non-leaf children ending before y.Then we make x and x children of x such that x is before y and y is before x .If this results in any internal node having no leaf-children and only one child, we merge this node with its parent.(Note that this can only happen to x or x .)This ensures that for every permutation expressed by T , the the subsequence of active vertices has the neighbors of a i as a sux.
Note that every non-leaf of T (i−1) s is also a non-leaf in T with the same set of leaves in its subtree.In the pre-order traversal of any ordered tree obtained from T , the non-leaves of T (i−1) s are visited in the same order as in the pre-order traversal of any ordered tree obtained from T (i−1) s .This implies that each permutation expressed by T is also expressed by T (i−1) s .Moreover, invariant (I2) holds locally for T .
The marked leaf-children of any half-marked node x of T (i−1) s can be placed anywhere before, between, or after its marked children, but not before y (since y has both marked and unmarked children).Symmetrically, the unmarked leafchildren of any half-marked node x of T (i−1) s can be placed anywhere before, between, or after its unmarked children, but not after y.Hence, each permutation expressed by T (i−1) s that has the neighbors of a i as a sux of the subsequence of its active vertices is also expressed by T .Moreover, invariant (I1) holds locally for T .
Thus, the permutations expressed by T are exactly those expressed by T (i−1) s that have the neighbors of a i as a sux of their active subsequence.Now, we create the data structure T i ; see Fig. 3c.We set . Clearly, both invariants hold locally for T i 1 , . . ., T i s−1 .Next, we create a new semi-ordered tree T i s as follows.The tree T i s gets a new root r, to which we attach T and a new vertex z, in this order.Then we hang from z in this order.We further make the entering vertices leaf-children of z.Note that this allows them to mix freely before, after, or between the components G ki−1 .Finally, we set T i = (T i 1 , . . ., T i s ).In this way, the order of the components G 1) is maintained in the data structures for G i .In T i s , both invariants clearly hold for the non-leaf children of z and, as argued above, also for T .Furthermore, we ensure that the entering vertices can be placed exactly before, after, or between the components of G (i−1) that are completely adjacent to a i .Hence, both invariants hold for T i .
The decision problem of STICK A can easily be solved by this algorithm.Namely, by our invariants, any permutation σ B expressed by T |A| occurs as a permutation of the horizontal sticks in a STICK A representation of G. Thus, executing our algorithm for STICK AB on σ A and σ B gives us a stick representation of G.This concludes the proof of correctness for the connected case.
Disconnected graphs.To handle disconnected graphs, we rst identify the connected components H 1 , . . ., H t of G.We label each element of A by the index of the component to which it belongs.Now, observe that if σ A contains a pattern of indices a and a that alternate as in aa aa , then the given STICK A instance does not admit a solution.Otherwise, we can treat each component separately by our algorithm, and then nest the resulting representations.Namely, for each connected component H r , we run our STICK A algorithm (on σ A restricted to H r ) to obtain a realizable permutation σ Br of the horizontal sticks of H r .Now, since our connected components avoid the pattern aa aa , there is natural hierarchy of these components which we can use to obtain a total order σ B on the horizontal sticks of G from the permutations σ B1 , . . ., σ Bt .Finally, we can use this σ B , the given σ A , and G as an input to our STICK AB algorithm to obtain a representation.
Running time.The size of each data structure T p is in O(|B p |) since there are no degree-2 vertices in the trees and each leaf corresponds to a vertex in B p .In each event, the transformations can clearly be done in time proportional to the size of the data structures.Since |B p | ≤ |B| for each p and there are 2|A| events, we get the following running time.

Sticks of Fixed Lengths
In this section, we consider the case that, for each vertex of the input graph, its stick length is part of the input and xed.We denote the variants of this problem by STICK fix if the order of the sticks is not restricted, by STICK fix A if σ A is given, and by STICK fix AB if σ A and σ B are given.Unlike in the case with variable stick lengths, all three new variants are NP-hard; see Sections 3.1 and 3.2.Surprisingly, STICK fix AB can be solved eciently by a simple linear program if the input graph contains no isolated vertices (i.e., vertices of degree 0); see Section 3.3.With our linear program, we can check the feasibility of any instance of STICK fix if we are given a total order of the sticks on the ground line.With our NP-hardness results, this implies NP-completeness of STICK fix , STICK fix A , and STICK fix AB .

STICK fix
We show that STICK fix is NP-hard by reduction from 3-PARTITION, which is strongly NP-hard [12].In 3-PARTITION, one is given a multiset S of 3m integers s 1 , . . ., s 3m such that, for i ∈ {1, . . ., 3m}, C/4 < s i < C/2, where C = ( 3m i=1 s i )/m, and the task is to decide whether S can be split into m sets of three integers, each summing up to C. Theorem 3.1 STICK fix is NP-complete.
Proof: As mentioned at the beginning of this section, NP-membership follows from our linear program (see Theorem 3.7 in Section 3.3) to test the feasibility of any instance of STICK fix when given a total order of the sticks on the ground line.
To show NP-hardness, we describe a polynomial-time reduction from 3-PARTITION to STICK fix .Given a 3-PARTITION instance I = (S, C, m), we construct a xed cage-like frame structure and introduce a number gadget for each number of S. A sketch of the frame is given in Fig. 4a.The purpose of the frame is to provide pockets, which will host our number gadgets (dened below).We add two long vertical (green) sticks y and z of length mC + 1 + 2ε and a shorter vertical (green) stick x of length 1 that are all kept together by a short horizontal (violet) stick w of some length ε 1.We use m + 1 horizontal (black) sticks p 1 , p 2 , . . ., p m+1 to separate the pockets.Each of them intersects y but not z and has a specic length such that the distance between two of these sticks is C ± ε.
Additionally, p 1 intersects x and p m+1 intersects a vertical (orange) stick o of length 2C.We use x and o to prevent the number gadgets from being placed below the bottommost and above the topmost pocket, respectively.It does not matter on which side of y the stick x ends up since each b i of a number gadget intersects y but neither x nor z.
For each number s i in S, we construct a number gadget; see Fig. 4b.We introduce a vertical (red) stick r i of length s i .Intersecting r i , we add a horizontal (blue) stick b i of length at least mC + 2. The stick b i intersects y and z, but neither x nor o.Due to these adjacencies, every number gadget can only be placed in one of the m pockets dened by p 1 , . . ., p m+1 .It cannot span multiple pockets.We require that r i and b i intersect each other close to their foot points, so we introduce two short (violet) sticks h i and v i one horizontal, the other verticalof lengths ε; they intersect each other, h i intersects r i , and v i intersects b i .Given a yes-instance I = (S, C, m) and a valid 3-partition P of S, the graph obtained by our reduction is realizable.Construct the frame as described before and place the number gadgets into the pockets according to P .Since the lengths of the three number gadgets' r i sum up to C ±3ε, all three can be placed into one pocket.After distributing all number gadgets, we have a stick representation.
Given a stick representation of a graph G obtained from our reduction, we can obtain a valid solution of the corresponding 3-PARTITION instance I = (S, C, m) as follows.Clearly, the shape of the frame is xed, creating m pockets.Since the sticks b 1 , . . ., b 3m are incident to y and z but neither to x nor to o, they can end up inside any of the pockets.In the y-dimension, each two number gadgets of numbers s k and s overlap at most on a section of length ε; otherwise r k and b or r and b k would intersect.Each pocket hosts precisely three number gadgets: we have 3m number gadgets, m pockets, and no pocket can contain four (or more) number gadgets; otherwise, there would be a number gadget of height at most (C + ε)/4 + 2ε, contradicting the fact that s i is an integer with s i > C/4.In each pocket, the height of the number gadgets would be too large if the three corresponding numbers of S would sum up to C + 1 or more.Thus, the assignment of number gadgets to pockets denes a valid 3-partition of S.
The sticks of lengths s 1 , . . ., s 3m can be simulated by paths of sticks with length ε each.We refer to them as ε-paths.Employing them in our reduction, it suces to use only three distinct stick lengths.Like a spring, an ε-path can be stretched (Fig. 5a) and compressed (Fig. 5c) up to a specic length.We will exploit the following properties regarding the minimum and the maximum size of an ε-path.First, we describe the modications of the frame structure, which are also depicted in Fig. 7a.Instead of the vertical (green) sticks x, y, and z used to x all pockets, we have two vertical sticks y j and z j of length 3Cm for j ∈ {1, . . ., m + 1}.Instead of the sticks p 1 , . . ., p m+1 of dierent lengths, we use horizontal (black) sticks p 1 , . . ., p m+1 each with length Cm to separate the pockets.The stick p j intersects y k , z k for all k ∈ {j + 1, . . ., m + 1} and y j but not z j .All pairs (y j , z j ) are kept together by a stick of length ε.For each two neighboring pairs (y j , z j ) and (y j+1 , z j+1 ), these sticks of length ε are connected by an ε-path of 2C/ε sticks.According to Lemma 1, this eects a maximum distance of (C/ε) • ε ± ε = C ± ε between each two pairs of (y j , z j ) and (y j+1 , z j+1 ).Accordingly, the pockets separated by the sticks p 1 , . . ., p m+1 have height at most C ± 2ε, similar as in the proof of Theorem 3.1.We keep the vertical (orange) stick o as in Fig. 4a to prevent number gadgets from being placed above the topmost pocket, but now o has length 3Cm.
Second, we describe the modications of the number gadgets for each number s i for i ∈ {1, . . ., 3m}, which are also depicted in Fig. 7b.We keep a long stick b i similar to b i now with length 3Cm.We replace r i (together with h i and v i ) by an ε-path of 6s i /ε − 4 sticks.We make the rst stick of the ε-path intersect b i .By Lemma 1, this ε-path has a stick representation with height s i + δ for any δ > 0, but there is no stick representation with height s i − 2 3 ε or smaller.Clearly, these number gadgets can only be placed into one pocket since none of their sticks intersects a p j for j ∈ {1, . . ., m + 1}.
Hence, we can represent a yes-instance of 3-PARTITION as such a stick graph if and only if the ε-paths of the number gadgets are (almost) as much compressed as possible (to make the number gadgets small enough) and the . . . . . . . . .ε-paths between the (y j , z j )-sticks are (almost) as much stretched as possible (to make the pockets tall enough).Using this, the proof is the same as in Theorem 3.1.

STICK fix
A and STICK fix

AB
We show that STICK fix A and STICK fix AB are NP-hard by reducing from MONOTONE-3-SAT, which is NP-hard [21].In MONOTONE-3-SAT, one is given a Boolean formula Φ in CNF where each clause contains three distinct literals that are all positive or all negative.The task is to decide whether Φ is satisable.

Theorem 3.3 STICK fix
A is NP-complete.Proof: Recall that, as mentioned before, NP-membership follows from our linear program (see Theorem 3.7 in Section 3.3) to test the feasibility of any instance of STICK fix when given a total order of the sticks on the ground line.To show NP-hardness, we describe a polynomial-time reduction from MONOTONE-3-SAT to STICK fix A .A schematization of our reduction is depicted in Figs. 8, 9, and 10.
Given a MONOTONE-3-SAT instance Φ over variables x 1 , . . ., x n , we construct a variable gadget for each variable as depicted in Fig. 8. Inside a (black) cage, there is a vertical (red) stick r i with length 1 and from the inside a long horizontal (green) stick g i leaves this cage.We can enforce the structure to be as in Fig. 8 as follows.We prescribe the order σ A of the vertical sticks as in Fig. 8. Since a i+1 has length ε 1, the horizontal (black) stick h i intersects the two vertical (black) sticks v i+1 and a i+1 close to its foot point.Since we have prescribed σ A (a i+1 ) < σ A (r i ) < σ A (v i ), we see that r i is inside the cage bounded by h i and v i and xes its heightas it does not intersect h i making the sticks h i and v i intersect close to their end points (both have length 1 + 2ε).Moreover, r i cannot be below h i−1 because a i is shorter than r i and intersects h i−1 to the right of r i .This leaves the freedom of placing g i above or below r i (as g i does not intersect r i ) but still with its foot point inside the cage formed by h i and v i because it intersects v i , but neither v i−1 nor v i+1 .
We say that the variable x i is set to false if the foot point of g i is below the foot point of r i , and true otherwise.For each x i , we add two long vertical (green) sticks y i and z i that we keep close together by using a short horizontal (violet) stick of length ε (see Fig. 9 on the bottom right).We make g i intersect y i but not z i .The three sticks g i , y i , and z i get the same length i .Hence, y i and g i intersect each other close to their end points as otherwise g i would intersect z i .We choose 1 suciently large such that the foot point of y 1 is to the right of the clause gadgets (see Fig. 9) and for each i with i ≥ 2, we set i = i−1 + 1 + 3ε.Now compare the end points of g i when x i is set to false and when x i is set to true relative to the (black) cage structure.When x i is set to true, the end point of g i is 1 ± 2ε above and 1 ± 2ε to the left compared to the case when x i is set to false.Observe that, since g i and y i intersect each other close to their end points, this oset is also pushed to y i and z i and their foot points.Consequently, the position of the foot point of y i (and z i ) diers by 1 ± 2ε relative to the (black) frame structure depending on whether x i is set to true or false.Our choice of i allows this movement.In other words, no matter which truth value we assign to each x i , there is a stick representation of the variable gadgets respecting σ A .Var: Negative clause gadget (empty sub-stripe at the top) Figure 10: Clause gadget in our reduction from MONOTONE-3-SAT to STICK fix A .Here, a clause gadget for each of the eight possible truth assignments of a MONOTONE-3-SAT clause is depicted.In particular, it shows that the (blue) isolated vertical stick ts inside the gadget if and only if the corresponding clause is satised.E.g., tf t means that the rst variable is set to true, the second to false, and the third to true. each horizontal (orange) stick o that is assigned to x i intersect y i and all y j and z j for j < i, but not z i or y k or z k for any k > i.Thus, o intersects y i close to o's end point.We choose the length of each such o so that its foot point is at the bottom of its sub-stripe if x i is set to false or is at the top of its sub-stripe if x i is set to true.Within the positive and the negative clause gadgets, this gives us two times eight possible congurations of the orange sticks depending on the truth assignment of the three variables of the clause (see Fig. 10).Within each clause gadget, we have a vertical (blue) stick b of length 2, which does not intersect any other stick.Each horizontal (black) stick that bounds a clause gadget intersects a short vertical (black) stick of length ε to force b into its designated clause gadget.
Clearly, if Φ is satisable, there is a stick representation of the STICK fix A instance obtained from Φ by our reduction by placing the sticks as described before (see also Fig. 9).In particular, each blue stick can be placed in one of the ways depicted in Fig. 10.
On the other hand, if there is a stick representation of the STICK fix A instance obtained by our reduction, Φ is satisable.As argued before, the shape of the (black) frame structure of all gadgets is xed by the choice of the adjacencies and lengths in the graph and σ A .The only exibility is, for each i ∈ {1, . . .n}, whether g i has its foot point above or below r i .This enforces one of eight distinct congurations per clause gadget.As depicted in Fig. 10, precisely the congurations that correspond to satisfying truth assignments are realizable.Thus, we can read a satisfying truth assignment of Φ from the variable gadgets.
Our reduction can obviously be implemented in polynomial time.
In our reduction, we enforce an order of the horizontal sticks.So, prescribing σ B makes it even easier to enforce this structure.Hence, we can use exactly the same reduction for STICK fix AB .
Corollary 3.4 STICK fix AB (with isolated vertices in A or B) is NP-complete.Proof: Given a MONOTONE-3-SAT instance Φ, consider the construction described in the proof of Theorem 3.3.We use the same graph, the same stick lengths and the same ordering σ A of the vertical sticks.Now, we additionally prescribe the order of the remaining horizontal sticks as depicted in Fig. 9 via σ B .This denes an instance of STICK fix AB .Clearly, the ordering of the horizontal sticks σ B neither aects the placement of the vertical isolated (red) sticks inside a variable gadget nor does it aect the placement of the vertical isolated (blue) sticks inside a clause gadget.Moreover, there was only one possible ordering of the horizontal sticks in the construction described in the proof of Theorem 3.3.Thus, its correctness proof applies here as well.
The reduction we described before uses isolated vertices inside the variable and the clause gadgets.In the case of STICK fix AB , this is indeed necessary to show NP-hardness.This is not true for STICK fix A , which remains NP-hard (and hence is NP-complete due to our linear program) even without isolated sticks.

Corollary 3.5 STICK fix
A without isolated vertices is NP-complete.Proof: We use the same reduction as in the proof of Theorem 3.3, but we additionally add, for each isolated stick, a short stick of length ε 1 that only intersects the isolated stick; see Fig. 11.In each variable gadget, for the isolated vertical (red) stick r i , we add a short horizontal (violet) stick w i of length ε.Similarly, in each clause gadget, for the isolated vertical (blue) stick b j , we add a short horizontal (violet) stick w j of length ε.After these additions, no isolated sticks remain.
Observe that, for any placement of the isolated (red and blue) sticks inside their gadgets in the proof of Theorem 3.3, we can add the new horizontal (violet) stick since it has length only ε.Moreover, since these new (violet) sticks are horizontal, we do not get any new ordering constraints in the version STICK fix A .We therefore conclude that the rest of the proof still holds.In this section, we constructively show that STICK fix is eciently solvable if we are given a total order of the vertices in A ∪ B on the ground line.Note that if there is a stick representation for an instance of STICK AB (and consequently also STICK fix AB ), the combinatorial order of the sticks on the ground line is always the same except for isolated vertices, which we formalize in the following lemma.The proof also follows implicitly from the proof of Theorem 2.1.Lemma 3.6 In all stick representations of an instance of STICK AB , the order of the vertices A ∪ B on the ground line is the same after removing all isolated vertices.This order can be found in time O(|E|).
Proof: Assume there are stick representations Γ 1 and Γ 2 of the same instance of STICK AB without isolated vertices that have dierent combinatorial arrangements on the ground line.Without loss of generality, there is a pair of sticks (a, b) ∈ A × B such that in Γ 1 , a comes before b, while in Γ 2 , a comes after b (see Fig. 12).Clearly, a and b cannot be adjacent.Since a is not isolated, there is a b that is adjacent to a and comes before b.Analogously, there is an a that is adjacent to b and comes after a.In Γ 2 , stick b, stick a , and the ground line dene a triangular region T (see Fig. 12b), which completely contains a since a occurs between b and a , but is adjacent to neither of them.However, b is outside of T as it comes before b.This contradicts b and a being adjacent.The unique order can be determined in O(|E|) time as described in Section 2.
We are given an instance of STICK fix and a total order v 1 , . . ., v n of the vertices (n = |A| + |B|) with stick lengths 1 , . . ., n .We create a system of dierence constraints, that is, a linear program Ax ≤ b where each constraint is a simple linear inequality of the form x j − x i ≤ b k , with n variables and m ≤ 3n − 1 constraints.Such a system can be modeled as a weighted graph with a vertex per variable x i and a directed edge (x i , x j ) with weight b k per constraint.The system has a solution if and only if there is no directed cycle of negative weight.In this case, a solution can be found in O(nm) time using the BellmanFord algorithm.In the following, we describe how to construct such a linear program for STICK fix .For each stick v i , we create a variable x i that corresponds to the x-coordinate of v i 's foot point on the ground line, with x 1 = 0. To ensure the unique order, we add n − 1 constraints x i+1 − x i ≤ −ε for some suitably small ε and i = 1, . . ., n − 1.
Let v i ∈ A and v j ∈ B. If (v i , v j ) ∈ E, then the corresponding sticks have to intersect, which they do if and only if x j − x i ≤ min{ i , j }.If i < j and (v i , v j ) / ∈ E, then the corresponding sticks must not intersect, so we require x j − x i > min{ i , j } ≥ min{ i , j } + ε.This easily gives a system of dierence constraints with O(n 2 ) constraints.We argue that a linear number suces.
Let v i ∈ A. Let j be the largest j such that (v i , v j ) ∈ E and j ≥ i .We add a constraint x j − x i ≤ i .Further, let k be the smallest k such that (v i , v k ) / ∈ E and k ≥ i .We add a constraint x k − x i > i ⇔ x i − x k ≤ − i − ε.Symmetrically, let v i ∈ B. Let j be the smallest j such that (v j , v i ) ∈ E and j > i .We add a constraint x i − x j ≤ i .Further, let k be the largest k such that (v k , v i ) / ∈ E and k > i .We add a constraint We now argue that these constraints are sucient to ensure that G is represented by a solution of the system.Let v i ∈ A and v j ∈ B. If i > j, then the corresponding sticks cannot intersect, which is ensured by the xed order.So assume that i < j.If j ≥ i and (v i , v j ) ∈ E, then we either have the constraint x j − x i ≤ i , or we have a constraint x k − x i ≤ i with i < j < k; together with the order constraints, this ensure that x j − x i ≤ x k − x i ≤ i .If j ≥ i and (v i , v j ) / ∈ E, then we either have the constraint x i − x j ≤ − i − ε, or we have a constraint x i − x k ≤ − i − ε with i < k < j; together with the order constraints, this ensure that x i − x j ≤ x i − x k ≤ − i − ε.Symmetrically, the constraints are also sucient for j < i .We obtain a system of dierence constraints with n variables and at most 3n − 1 constraints proving Theorem 3.7.By Lemma 3.6, there is at most one realizable order of vertices for a STICK fix AB instance without isolated vertices, which can be found in linear time and proves Corollary 3.8.Theorem 3.7 STICK fix can be solved in O((|A| + |B|) 2 ) time if we are given a total order of the vertices.
(i) We have a valid representation of the subgraph of G induced by the vertices b 1 , . . ., b βi , a 1 , . . ., a i .
(i) a set U v of unordered children, (ii) a set O v of ordered children, and (iii) a xed permutation π v of O v ; see Fig. 1.

5 (d) enter event of a 5 Figure 2 :
Figure2: An example for the data structures and a drawing corresponding to a realizable permutation of B p for a graph G with πa = (a1, . . ., a k ).Vertices in A are drawn as squares; vertices in B are drawn as circles.The vertices and edges are colored by the entering event in which they appear.Dead vertices are drawn as empty circles; their edges are dotted.In (d), the leaves are permuted in the order in which they are drawn.

Figure 3 :
Figure 3: Construction of T i .Leaves are drawn as small circles.The leaves at the new node z are the entering vertices.Only active vertices are shown.

.
If all active vertices in B(i−1) s are neighbors of a i , then we are already done.
si(b) number gadget for the number s i

Figure 4 :
Figure 4: Gadgets of our reduction from 3-PARTITION to STICK fix .

Figure 5 :
Figure 5: Three stick representations of an ε-path with twelve sticks.

Figure 6 :
Figure 6: Construction of a compressed stick representation of an ε-path

Figure 7 :
Figure 7: Gadgets of our reduction from 3-PARTITION to STICK fix with three stick lengths.

Figure 8 :
Figure 8: Variable gadget in our reduction from MONOTONE-3-SAT to STICK fix A .

Figure 9 :Var: x 1 Var: x 2 Var: x 3
Figure 9: Illustration of our reduction from MONOTONE-3-SAT to STICK fix A variable gadget without isolated stick b j (c) clause gadget with isolated stick b j w j (d) clause gadget without isolated stick

Figure 11 :
Figure 11:  We add a short horizontal (violet) stick wi (or w j ) that intersects ri (or bj) to avoid isolated sticks in a variable (or clause) gadget for variable xi (or clause Cj).
a comes before b (valid representation) a comes after b (no representation)

Figure 12 :
Figure 12: Trying to represent a subgraph of the edges ab and a b while respecting σA and σB.

Table 1 :
Previously known and new results for deciding whether a given bipartite graph G = (A ∪B, E) is a stick graph.In O(•), we dropped | • |.We abbreviate vertices by vtc., NP-complete by NPC, Theorem by T., and Corollary by C.
In this section, we provide algorithms that solve the STICK AB problem in O(|A|+ |B| + |E|) time (see Section 2.1, Theorem 2.1) and the STICK A problem in O(|A| • |B|) time (see Section 2.3, Theorem 2.2).Between these subsections, in Section 2.2, we describe semi-ordered trees, an essential tool reminiscent of PQ-trees that we will use for the latter algorithm.This tool will allow us to express the dierent ways one can order the horizontal segments for a given instance of STICK A .2.1 Solving STICK AB in O(|A| + |B| + |E|) time De Luca et al. [10] showed how to compute, for a given graph G = (A ∪ B, E) and orders σ A and σ B , a STICK AB representation in O(|A| • |B|) time (if such a representation exists).We improve upon their result in this section.Namely, we prove the following theorem.Theorem 2.1 STICK AB can be solved in O(|A| + |B| + |E|) time.