Journal of Graph Algorithms and Applications towards an Optimal Algorithm for Recognizing Laman Graphs

A graph G with n vertices and m edges is a generically minimally rigid graph (Laman graph), if m = 2n−3 and every induced subset of k vertices spans at most 2k − 3 edges. Laman graphs play a fundamental role in rigidity theory. We discuss the Verification problem: Given a graph G with n ver-tices, decide if it is Laman. We present an algorithm that recognizes Laman graphs in O(Tst(n) + n log n) time, where Tst(n) is the best time to extract two edge disjoint spanning trees from a graph with n vertices and 2n − 2 edges, or decide no such trees exist. So far, it is known that Tst(n) is O(n 3/2 √ log n).


Introduction
A graph G = (V, E) with n = |V | vertices and m = |E| edges is a generically minimally rigid graph (also called Laman graph [10]), if m = 2n − 3 and every k-vertex subgraph has at most 2k − 3 edges. Laman graphs play a fundamental role in rigidity theory: they characterize minimally rigid planar bar-and-joint systems that appear in robotics, sensor and network topologies and polymer physics. (A system of fixed-length bars and flexible joints connecting them is minimally rigid if it becomes flexible once one bar is removed).
In this paper we address the Verification problem: Given a graph G with n vertices, decide if it is Laman.

Previous work
Most existing verification algorithms take quadratic time in the number of input vertices to recognize Laman graphs [1,7,8,11,17]. A very elegant and simple algorithm is the pebble game algorithm, first proposed by Jacobs and Hendrickson [9], and generalized later on by Streinu, Lee, and Theran in a number of papers [6,11,15,16]. The pebble game algorithm solves the verification problem in O(n 2 ) time.
The characterizations of Laman graphs with tree partitions are due to Recski [14], Crapo [3] and Lovasz and Yemini [12]. Lovasz and Yemini proved that a graph G = (V, E) is Laman if and only if, for each edge e ∈ E, the multigraph G ∪ {e} is the union of two edge disjoint spanning trees; Recski proved this statement also holds for any e ∈ E. Crapo showed that graph is Laman if and only if it is decomposable into three disjoint trees such that every vertex is in every two of those trees and no nontrivial subrtrees of distinct trees have the same set of vertices. Verifying any of these conditions directly requires Ω(n 2 ) time.
A subquadratic time algorithm for the verification problem is due to Gabow and Westermann [5]. It requires O(n 3/2 √ log n) time and solves the problem in two steps: (1) Find a 2-forest of G ∪ {e} (two edge disjoint spanning trees), which is done in O(n 3/2 √ log n) time, and (2) Test if a data structure computed in step (1), called top clump, is empty: this is done in O(n log n) time. Thus, step (2) is coupled with step (1), in the sense that if two edge disjoint spanning trees are given to step (2), computed by some arbitrary method, then step (2) should be changed and could require asymptotically larger time. 1 A different verification method was proposed recently by Bereg [1]. Bereg's algorithm performs a step-by-step decomposition of G, aiming to construct a hierarchical decomposition H of G, called a red-black hierarchy (RBH). It is proven in [1] that G is a Laman graph if and only if H is a RBH.
Hierarchy. [1] A hierarchy H(G, T h , α, β) for a given graph tree. The function α : V → L(T h ), defines a one-to-one correspondence between the vertices of V and the leaves of the tree, denoted as L(T h ). The function ) of H (called cross edge), so that β 1 (u, v) and β 2 (u, v) are ancestors, but not common ancestors, of α(u) and α(v), respectively. Red-black hierarchy.
[1] A red-black hierarchy H(G, T h , α, β) is a hierarchy satisfying the following conditions: • The root of the tree T h has exactly two children (root rule); • A vertex is the only child of its parent if and only if it is a leaf (leaf rule); • For any cross edge its endpoints have the same grandparent but different parents in the tree (cross-edge rule); • Cross edges connect all grandchildren of a vertex and form a tree (tree rule).
The construction of the RBH in [1] has three major phases. (1) A copy of an edge of G, e add , is added to G and two edge-disjoint spanning trees, red tree T r and black tree T b are computed for G * = G ∪ {e add } using a known method (if no such trees exist, then G is not Laman), see Figure 1. An O(n 2 ) time algorithm is used to obtain the trees.
(2) A decomposition of G * is performed and a characterizing hierarchy H = H(G * ) is constructed in correspondence with the steps of the decomposition (Figure 2), which is done in O(n 2 ) time.
(3) A certification whether H satisfies the rules of a RBH is performed in O(n) time.
Since steps (2) and (3) do not depend on how step (1) is performed, this method decouples the computation of the two edge disjoint spanning trees in step (1) from the rest of the computation. (After the preliminary version of this article was published, an improved, O(n log n) time solution for step (2), was posted at [2] that also uses O(n 3/2 √ log n) time algorithm for step (1)).

Our results
Let T st (n) be the time to find two edge disjoint spanning trees in G. We present an O(T st (n)+n log n) time verification algorithm based on a simple observation: from Corollary 4 in [1], it follows that it is not necessary to actually construct H to decide G is Laman; we only need to decide whether a RBH decomposition H exists for G. Thus, steps (2) and (3) from the above Bereg's algorithm become: (2) use the two spanning trees to decide whether G admits a RBH decomposition. Our algorithm has two steps: (1) Compute two edge disjoint spanning trees by the best possible method. We use the O(n 3/2 √ log n) time algorithm from [5] since this is the best we know (if, say, a simple O(n log n) time algorithm is discovered for this part, we will use that one). (2) Given two edge disjoint spanning trees for G, we give a solution for deciding whether G admits a RBH decomposition, that uses depth-first search and segment trees only, and takes O(n log n) time. This step is independent of how step (1) is done.
At the end of step (2) we know if G is Laman or not. Moreover, we also show that the RBH can be actually constructed in O(n log n) time using a two steps procedure that is simple and easy to implement. Thus, our algorithm decouples step (1) from step (2), to take advantage of future improvements on step (1), and solves the second step of the verification in O(n log n) time instead of O(n 2 ) time.
We summarize our results below.
Theorem 1 Given a graph G with n vertices and m edges deciding whether G is a Laman graph can be done in O(T st (n) + n log n) time, where T st (n) is the time to extract two edge disjoint spanning trees from G or decide no such trees exist.
Theorem 2 Given two edge-disjoint spanning trees for G * , a red-black hierarchy for G * , if it exists, can be constructed in O(n log n) time.
In the rest of the paper we explore the properties of the RBH, provide the proofs for the above theorems and give implementation details for our algorithm. From now on, we assume familiarity of the reader with the decomposition and hierarchy construction processes described in [1].

A sufficient condition
We begin by showing that if all edges are removed from G during the decomposition process, the graph H constructed from the decomposition is always a RBH and thus G is a Laman graph.
Theorem 3 (i) The graph H constructed from the decomposition always satisfies the four rules of red-black hierarchy and (ii) The graph G is a Laman graph if and only if all edges are removed from G during the decomposition process.
The correctness of the above statement follows from Theorem 2 of [16], since the decomposition proceeding until all edges are removed is a special case of the (2,3)-pebble-game with colors decomposition [16]. We choose to prove it via red-black hierarchies to reveal some properties of the latter, described in the lemmas below. Notations. Anything marked by the subscript h in what follows refers to H. Let color(v h ) denote the color associated with node v h (red or black). If c = color(v h ) is red then c is black and vice versa. Vertices of H correspond to spanning trees of connected subgraphs of G.

Lemma 4
The four RBH rules always hold for the graph H that characterizes decomposition of any graph G * = G∪e add , if the edge set of G * can be partitioned into two edge-disjoint spanning trees.
Proof. Root rule. At the very first step, H is empty and a node r h of color c, corresponding to the spanning tree T c that does not contain the added edge e add , is created in H. The node r h is the root of H. Then, e add is deleted from the other tree T c , which necessarily creates exactly two trees of color c in G * and exactly two nodes of color c in H that are children of r h , corresponding to these two trees. Thus, the root rule always holds.
Leaf rule. If a vertex v h is the only child of its parent then v h is a leaf. At the step when v h was created, the decomposition process has stopped for C(v h ): there was just one tree of color color(v h ) in C(parent(v h )) and just one tree of color color(v h ) (otherwise C(parent(v h )) would have been partitioned further and v h would have siblings). Hence, the vertex v h corresponding to C(v h ) is a leaf in H.
A leaf vertex cannot have any siblings. Suppose there is a vertex y h having k > 1 children x i h , i = 1, . . . , k and x j h is a leaf. The vertex y h corresponds to a connected subgraph spanned by a tree of color c = color(y h ) and a spanning forest of k trees of color c; x j h corresponds to a connected subgraph C(x j h ), spanned by a tree of color c and a forest of color c. If the forest contains more than one tree, at the next step of the decomposition the edges of color c connecting the trees of the spanning forest will be deleted, the spanning tree of color c will split into at least two different trees and corresponding vertices will be created in H as children of x i h . Hence, x j h cannot be a leaf vertex. If the spanning forest of C(x j h ) contains just one tree, then a vertex corresponding to that tree, of color c, is created in H as a child of x j h and x j h cannot be a leaf vertex, a contradiction.
Cross-edge rule. A cross edge is added between any two vertices u h and v h at step i if their corresponding vertex sets V (u h ) and V (v h ) previously belonged to one connected subgraph C u,v and got separated at step i − 1 by removing the edge with endpoints in V (u h ) and V (v h ). At level i − 2 of H there is always a vertex that corresponds to C u,v . The vertices at the same level of H correspond to connected subgraphs that are disjoint subgraphs of G. Hence, no other vertex at level i − 2 of H can correspond to a connected subgraph containing V (u h ), V (v h ), their subsets, or the union of their subsets. The vertex corresponding to the connected subgraph C u,v is a common grandparent of u h and v h .
According to the construction rules, parents of u h and v h in H correspond to different connected subgraphs and cannot coincide.
Tree rule. If k edges are removed from the tree T ⊂ E(G) spanning the vertex set V (v h ) that corresponds to some vertex v h of H, k + 1 new trees result from T and k + 1 nodes are created as grandchildren of v h in H. For each edge e deleted from T , exactly one cross edge is added between the grandchildren of v h . Each grandchild of v h gets a cross edge incident to it, thus cross edges form a tree spanning all the grandchildren of v h . Proof. There is a cross edge e h = (u h , v h ) in H for each edge e = (u, v) of G.
The edge e is deleted from G when it crosses the cut separating u from v, a cross edge is then added between the vertices of H corresponding to the connected components of u and v at the current step.
There is one-to-one correspondence between the leaves of T h and the vertices of G: If the decomposition continues until all edges are removed, each vertex v of G is eventually disconnected from the rest of the graph by deleting an edge of some color c. A vertex l h corresponding to a tree of color c spanning the connected subgraph C v = {v} is then created in H. Since C v cannot be split further, the decomposition stops for C v and l h becomes a leaf vertex of T h . Also, there is no leaf vertex in H that does not correspond to a vertex of G.
Suppose there exists such vertex in H. Then, it corresponds to a tree spanning a connected subgraph C x , with |C x | > 1, i.e. C x contains edges that were not deleted during the decomposition of G, a contradiction.
For each edge e h its endpoints u h and v h are ancestors of α(u) and α(v), respectively, but they are not their common ancestors. Proof. If there are non-deleted edges of G when the decomposition stops, then there are no corresponding edges for them in H. In addition, we do not have a one-to-one map from V to L(T h ): some leaves of T h correspond to connected subgraphs containing several vertices. 2 This concludes the proof of Theorem 3. Thus, building H is not required for certifying Laman graphs. It is sufficient to perform the decomposition of G according to the rules from [1] and then check whether there are edges left in G when the decomposition ends.

Decomposition
Our main goal now is to speed up the decomposition process. At each step of the decomposition edges of only one color are deleted. The groups of red and black edges are deleted in turns. At each step, except the first and the last ones, at least one edge is deleted from G. Let g = (g 2 , g 3 , . . . , g k ) be a grouping of some (possibly all) edges of G, such that all edges of a group g i were deleted from G at step i. Instead of H, we use g to characterize the graph decomposition.

Algorithm
We slightly alter the graph decomposition algorithm from [1]. The edges to be deleted at the next step are identified at the end of the preceding step and are marked for deletion. At the first step, e add is marked for deletion (and no other action is performed). Each iterative step in G consists of removing the marked edges of some color c and identifying and marking the edges (of the opposite color c) crossing the cuts induced by removing the marked edges.
We note that once the original graph has split into several connected subgraphs, the decomposition proceeds independently on each subgraph, and the problem of finding the edges to be deleted at the subsequent step can be viewed as several independent subproblems, each on a distinct connected subgraph. We also note that deletion of any edge e = (u, v) from its tree (of color color(e)), where u is a parent of v in a depth-first-search (DFS) ordering of the tree of color color(e), always forms two trees such that one of them is rooted at v and all nodes in that tree are descendants of v.
Consider the graph G * and its two edge disjoint spanning trees T c and T c , rooted at vertices r c and r c , respectively. Let DF S(c) be the depth-first search traversal of G * starting at r c and using only edges of color c, where c is either red or black. We assign each vertex of G two DFS order numbers, one from DF S(red) and another one from DF S(black). New edges are never added to the trees, so the numbers never change. Whenever an edge e is mentioned in the following text as a vertex pair, the first vertex is always the parent of the second vertex in DF S(color(e)).
When an edge e = (u, v) of color c is deleted from a tree T c k rooted at some r c and spanning a connected subgraph C k , two trees emerge:  We identify such intervals using a segment tree data structure enhanced with two lists at each internal node, one sorted by the start time of the intervals stored at the node and one sorted by their finish time. A segment tree [13] is a balanced binary search tree that stores a set of intervals with endpoints from a finite set of abscissae (intervals corresponding to edges of color c, for example). Each of its nodes u has an interval I(u) associated with it and stores a list of input intervals intersecting I(u). Binary search in a segment tree allows to report the intervals containing a query point.
In our case, the endpoints of the intervals are integer numbers, so an interval containing a point p + ∆ or p − ∆, for any 0 < ∆ < 1 and integer p, contains the point p as well. First, we find the intervals with one endpoint before d c To ensure that each returned interval has exactly one endpoint in t we augment the standard segment tree by storing two sorted lists at each node, instead of just one list. With each node u, we store a list L f inish (u) of intervals that intersect I(u) that is sorted by the finish time of the intervals in non-decreasing order; similarly, the list L start stores the same intervals sorted by their starting time in non-increasing order. Both queries are given an additional parameter: f c [v] for the first one and d c [v] for the second one. The first query only scans the lists L f inish and reports the intervals that have their right endpoint no greater than f c [v]. The second query only scans at the lists L start and reports the intervals that have their starting point no later than d c [v]. Thus, this data structure allows us to return intervals with exactly one endpoint in t.
We also maintain an auxiliary list L for each segment tree T S . Each entry in that list corresponds to one interval and stores a list of pointers to interval's positions in L f inish and L start (the pointers are obtained when the interval is inserted into L f inish and L start ). Additionally, the entries of L f inish and L start should point to their corresponding entry in L. For each interval, O(log n) auxiliary data is stored.

Running time
To efficiently identify edges crossing the cuts at each step of the decomposition, we maintain two segment trees, one for the red intervals [d red [u] Each query with an edge (interval t) takes O(log n + k) time, where k is the number of intervals (crossing edges) reported: the query scans the lists L f inish (L start ) at each level of the segment tree, stopping each time when an interval with a right (left) endpoint greater than f c [v] (d c [v]) is encountered. To avoid reporting an interval more than once, the interval is deleted from the segment tree (including the sorted lists associated with the nodes that store it) right after it is returned by a query.
When an interval is deleted from T S a) a corresponding entry should be located in L, and b) all the entries in T S associated with that interval should be deleted. If we keep a pointer from each interval to the corresponding entry

The hierarchy reconstruction algorithm
The order in which edges are deleted from G during the decomposition determines the structure of the corresponding red-black hierarchy H, so given g, one can unambiguously construct H in top-down fashion according to the rules from [1]. In the original approach, to construct the i-th level of H, one has to know the spanning sub-trees at step i − 2 of the decomposition and to spend O(n) time figuring out what trees appear after removal of edges at the beginning of step i.
We consider the decomposition process in reverse order (i.e. start from n red and n black disjoint trees of one vertex each and add edges to them until two spanning trees of G are formed). The last group g k of g = (g 2 , g 3 , . . . , g k ) contains edges of some color c deleted at the very last step of the decomposition. Each endpoint v of edges of g k corresponds to a subtree of G of color c spanning only the vertex v. A leaf node v h = α(v) is added to the k-th level of H for each such vertex v. Only one leaf vertex is created for the endpoint shared by multiple edges from g k . For every edge (u, v) of g k a corresponding cross edge β(u, v) = (α(u), α(v)) is added to H. For every leaf vertex α(v) of H, its parent should be at level k − 1 of H, corresponding to a subtree in G that is of color c and spans only the vertex v. Such parent vertex v p h = parent(α(v)) is added to level k − 1 of H along with a tree edge connecting v p h and α(v) (we call this the parent creation rule). The vertices of H connected by a cross edge have the same grandparent. For every cross edge tree T j k formed at the k-th level, a vertex v g h is added to level k − 2 of H, as well as a tree edge connecting v g h and v p h , for every v h ∈ T j k . We have completed level k of H as well as added some elements to the two upper levels (see Figure 3). Algorithm. The algorithm takes g as an input and returns the corresponding RBH H. It relies on classical UNION-FIND data structure augmented with a few simple operations. A pointer to a vertex of H is associated with each set, and a function GET-VERTEX(s) returns the vertex pointed to by the set s. The resulting set of the UNION(s,t) operation points to the vertex that s used to point to. A canonical MAKE-SET(s) is modified to take an additional parameter v, the vertex of H that the newly created set should point to. A function REPRESENTATIVE(s) returns an element belonging to the set s. Two instances of UNION-FIND data structure are used. The sets of one instance point to vertices of some level i of H, the sets of another instance point to the parents of the vertices of the i th level. In the pseudocode below these instances are distinguished by subscripts a and a, such that if a = 0 then a = 1 and vice versa.

Conclusions
In this paper we discussed the problem of recognizing whether a given graph G with n vertices is Laman. We presented an algorithm that recognizes Laman graphs in O(T st (n) + n log n) time, where T st (n) is the best time to extract two edge disjoint spanning trees from a graph with n vertices and 2n − 2 edges, or decide no such trees exist. So far, it is known that T st (n) is O(n 3/2 √ log n). We notice that improvements to T st (n) would result in improvements to our algorithm. We leave improving T st (n) as an open problem.