Fully dynamic algorithms for bounded genus graphs

12 downloads 0 Views 245KB Size Report
Sep 9, 1997 - The algorithm runs in O(log2 n) amortized time per insertion, O(log3 n) ... tree of a graph with k di erent edge weights: O(klog3 n) amortized time.
Fully dynamic algorithms for bounded genus graphs Monika Rauch Henzinger  Louis Ibarra y 9 September 1997

Valerie King z

Abstract

We present a deterministic algorithm that maintains the connected components of a graph as edges are inserted and deleted, provided the genus of the graph is bounded by a xed constant. The algorithm runs in O(log2 n) amortized time per insertion, O(log3 n) amortized time per deletion, and O(log n= loglog n) worst-case time per query, where n is the number of vertices in the graph. This is the rst fully dynamic deterministic algorithm for connectivity in nonplanar graphs that runs in polylogarithmic time per operation. A consequence of our connectivity algorithm is fully dynamic algorithms for several other problems in bounded genus graphs.

1 Introduction A dynamic graph algorithm is an algorithm that maintains some graph property as changes are made in the graph. More precisely, a fully dynamic graph algorithm supports the following operations: (1) an update is the deletion or insertion of an edge, (2) a query is a question about the graph property. A semi-dynamic graph algorithm supports only deletions or only insertions. The query is typically a yes-no question, e.g., \Are vertices u; v connected?" or \Is the graph biconnected?". The operations must be performed on-line: the sequence of updates and queries is not known in advance. (There are also dynamic graph algorithms where the updates include vertex deletions and insertions [3, 26].) There are fully dynamic algorithms for a variety of graph properties, including connectivity [6, 7, 13, 16, 17, 18], biconnectivity [6, 7, 15, 23], 2-edge connectivity [14, 16], bipartiteness [6, 7, 16, 17], and minimum spanning trees [6, 13, 17]. (In the case of minimum spanning trees, an update may change an edge weight.) Deletions-only dynamic algorithms exist for connectivity [10, 24] and minimum spanning trees [16]. Insertions-only dynamic algorithms can be readily obtained for connectivity using disjoint-set union [27] and for minimum spanning trees using dynamic trees [25]. There are also numerous dynamic algorithms for planar graphs [1, 8, 9, 13, 19, 20, 23]. The survey by Feigenbaum and Kannan [11] describes most of these results. Let G = (V; E ) be an undirected graph with n vertices and (initially) m edges. The following fully dynamic algorithms are known for maintaining the connected components of G. The fastest known algorithms for general graphs run in O(log2 n) randomized time per update [16, 18] and O(n1=3 log n) deterministic time per update [17], amortized over (m + n) updates in both cases.  Systems Research Center, Digital Equipment Corporation, 130 Lytton Ave., Palo Alto, CA. Email: [email protected]. y Dept. of Computer Science, University of Victoria, Victoria, BC, Canada. Email: [email protected]. z Dept. of Computer Science, University of Victoria, Victoria, BC, Canada. Email: [email protected]. This research was supported by an NSERC Grant.

1

Eppstein et. al. [8] gave an algorithm for planar graphs that runs in O(log n) time per query, O(log n) amortized time per insertion, and O(log2 n) time per deletion. In this paper, we give an algorithm for bounded genus graphs that runs in O(log n= log log n) time per query, O(log2 n) amortized time per insertion, and O(log3 n) amortized time per deletion, amortized over (m + n) updates. This is the rst fully dynamic deterministic algorithm for nonplanar graphs that runs in polylogarithmic time per operation. It is also the rst fully dynamic algorithm | for any graph property | that exploits topological properties of nonplanar graphs. Like the algorithm by Eppstein et. al. [8], it allows insertions that preserve the genus of the graph (0 for planar graphs) but not the embedding, unlike [9, 13, 19, 20, 23]. Henzinger and King [17] implicitly used the composite data structure technique to transform a deletions-only minimum spanning tree algorithm into a fully dynamic algorithm, which is the fastest known fully dynamic deterministic algorithm for minimum spanning trees. We show the technique's versatility by using it to develop our fully dynamic algorithm for connectivity from a deletions-only connectivity algorithm of Reif [24]. Unlike the algorithm in [17], our algorithm requires a new implementation of Reif's algorithm (based on ET-trees), a correctness proof that does not rely on properties of minimum spanning trees, and an embedding algorithm used as a subroutine. Using our connectivity algorithm, we obtain the following fully dynamic algorithms for graphs with bounded genus: 1. Minimum spanning tree of a graph with k di erent edge weights: O(k log3 n) amortized time per update. 2. (1 + )-Approximation of the minimum spanning tree of a graph with edge weights between 1 and U : O(log3 n(log U )=) amortized time per update. 3. Bipartiteness: O(log3 n) amortized time per update and O(1) worst-case time per query (\Is the graph bipartite?"). 4. k-Edge witness: O(log3 n) amortized time per update and O(k log3 n) amortized time per query (\Does the removal of the given k edges disconnect the graph?"). Note that the 2-edge witness problem is equivalent to the cycle-equivalence problem. 5. Maximal spanning forest decomposition of order k: O(k log3 n) amortized time per update. A maximal spanning forest decomposition of order k is a sequence F1 ; : : :; Fk of edge-disjoint subgraphs of G such that Fi is a spanning forest (with one spanning tree per connected component) of the graph Gi = G ? [j 0, as follows: the spanning forest of Ai is set to F and for each j  i, the nontree edges of Aj (which are nontree edges of G by the invariant) are removed from Aj and added to Ai . Thus, immediately after building or rebuilding Ai , xi?1 is 0 and xi is equal to the number of nontree edges in Ai . Since Ai is a deletions-only data structure, we also initialize Ai with an embedding of genus at most g and the corresponding face trees; we show how to do this in Section 6. For each i > 0, we build or rebuild Ai whenever A0 is nonempty and i is the smallest positive integer such that xi  2i (implying that either i = 1 or xi?1 > 2i?1 ). Thus, we build or rebuild some Ai immediately after inserting any edge(s) into A0 . Since each Ai ; i > 0, functions as a deletions-only data structure between its rebuilds, the number of nontree edges of Ai is always at most 2i . In summary, the algorithm represents F and the composite data structure as follows:  F : represented by degree-(log n) ET-trees  A0: represented by an unordered set  Ai; i > 0: spanning forest represented by degree-2 ET-trees, which store the nontree edges of

Ai

To insert an edge e into G: If e connects di erent trees T1 ; T2 of F , then insert e into F (by joining T1 and T2 with e); otherwise, insert e into A0 and rebuild the appropriate Ai. To delete an edge e from G: Delete e from all data structures in which it appears and update the Ai 's as needed. If e was a tree edge of G, execute steps 1 and 2.

7

1. Let T1 ; T2 be the trees of F that contain e's endpoints. If e was a tree edge of Ai , let ei be the replacement edge of Ai (if any). Test every ei to determine whether it connects T1 and T2. Choose any such connecting edge e0 (if any) and insert it into F . 2. For every ei that was not chosen as e0 in step 1, insert ei into A0. Rebuild the appropriate Ai . Observe that an edge of G is added to the composite data structure in one of two ways: (1) a nontree edge of G is inserted into A0 , (2) the tree edges of G are copied into the spanning forest of an Ai ; i > 0, when Ai is built or rebuilt. Also, the spanning forests of the Ai 's are initially identical to F , but they subsequently evolve di erently. More precisely, when Ai is built or rebuilt, Ai 's spanning forest is set to F and Ai has some subset of the nontree edges of G. Until the next rebuild of Ai , (1) insertions into G do not a ect Ai , (2) deletions from G may cause Ai to split a tree and reconnect it with one of its nontree edges; this replacement edge is not necessarily the same replacement edge used by F or Aj ; j 6= i.

5.2 Correctness

Invariant The nontree edges of the Ai 's form a partition of the nontree edges of G. Lemma 2 The algorithm maintains the invariant. Proof The invariant holds initially since As is initialized with F and the nontree edges of G, and

A0 ; : : :; As?1 are empty. Consider an insertion into G. The inserted edge is inserted into either F or A0 , so the invariant holds after the insertion. Consider a deletion of e from G. Suppose e is a nontree edge of G. By the invariant, e is a nontree edge of some Ai , so the invariant holds after the deletion. Suppose e is a tree edge of G. By the invariant, e is not a nontree edge of any Ai . If e is a tree edge of Ai and ei (a nontree edge of Ai ) becomes a tree edge of Ai when e is deleted, then either ei is chosen as e0 , which means ei is inserted into F , or ei is inserted into A0 . Thus, the invariant holds after the deletion. Finally, consider the building or rebuilding of an Ai . Since the invariant holds and Ai 's spanning forest is initialized with F , then all the nontree edges of Aj ; j  i; become nontree edges of Ai , so that the invariant continues to hold. Hence, the algorithm maintains the invariant. 

Lemma 3 If Ai; i > 0; has at least one nontree edge, then for each tree edge e of Ai, either e is in

F or e is a nontree edge of some Aj ; j < i. Proof Immediately after Ai is built or rebuilt, Ai's spanning forest is identical to F and the lemma holds. Suppose a tree edge of Ai is deleted and as a result, a nontree edge ei of Ai becomes a tree edge of Ai . Then ei is inserted into either F or A0 . In the rst case, ei remains in F until it is deleted from F (and Ai ), so the lemma holds. In the second case, some Aj ; j > 0; is rebuilt and ei is moved to Aj . If j > i, then Ai is left with no nontree edges until its next rebuild. If j = i, then Ai itself is rebuilt. If j < i, then ei becomes a nontree edge of Aj and we apply the same argument to Aj (in case ei becomes a tree edge of Aj or some Ak ; k > j; is built or rebuilt). Thus, the lemma always holds.  When a tree edge e of G is deleted, we distinguish between a replacement edge in G (which is a nontree edge of G that connects the trees of F containing e's endpoints) and a replacement edge in Ai (which is a nontree edge of Ai that connects the trees of Ai containing e's endpoints). The following theorem proves correctness.

8

Theorem 4 If a tree edge of G is deleted, then the algorithm nds a replacement edge in G if one

exists.

Proof Suppose tree edge e is deleted from G and there exists a replacement edge in G. By the

invariant, every replacement edge in G is a nontree edge of some Ai ; i > 0. Let i be the smallest integer such that some nontree edge e of Ai is a replacement edge in G. Let T1; T2 be the trees of F that contain e's endpoints after e is deleted, so that e connects T1 and T2. Consider the state of the composite data structure immediately before e is deleted. Claim If a tree edge f of Ai connects T1 and T2, then f = e. Proof If f is a nontree edge of G (so that f is a replacement edge in G), then by Lemma 3, f is a nontree edge of some Aj ; j < i, contradicting the choice of i. Thus, f must be a tree edge of G. Since e is the only tree edge of G connecting T1 and T2, then f = e.  Since e is a nontree edge of Ai , there is a path P in Ai 's spanning forest between e 's endpoints. Since P is a path from a vertex in T1 to a vertex in T2 and any edge with an endpoint in T1 [ T2 has its other endpoint in T1 [ T2 (because T1 [ T2 is a maximally connected component of G), then some edge of P connects T1 and T2. By the claim, this edge is e. Thus, e is a tree edge in Ai and e is a replacement edge in Ai . We now show that any replacement edge in Ai is also a replacement edge in G. Consider the state of Ai after e is deleted but before a replacement edge is inserted into Ai 's spanning forest. Let Ti1 ; Ti2 be the trees of Ai 's spanning forest that contain e's endpoints. Since e is a replacement edge in both Ai and G, then e 's endpoints connect Ti1 and Ti2 and also T1 and T2. Without loss of generality, suppose one endpoint of e is in Ti1 \ T1 and its other endpoint is in Ti2 \ T2. Now if any vertex of Ti1 is in T2, then there is an edge of Ti1 that connects T1 and T2 . By the claim, this edge is e, a contradiction since e has been deleted. Thus, V (Ti1 )  V (T1), where V (T ) denotes the vertex set of tree T . Similarly, V (Ti2 )  V (T2). This implies that any replacement edge ei in Ai (connecting Ti1 and Ti2 ) is also a replacement edge in G (connecting T1 and T2). Thus, ei is tested in step 1 above, which guarantees the algorithm nds a replacement edge in G. 

5.3 Analysis and implementation

In this subsection, we assume that when an Ai is built or rebuilt, we can nd an embedding of Ai with genus at most g and build the corresponding face trees in O(2i log n) time. Section 6 gives an algorithm that does this using dynamic trees. Thus, we maintain each Ai 's spanning forest with ET-trees (for use by the deletions-only data structure) and with dynamic trees (for use by the embedding algorithm). Initialization We compute the spanning forest F and build its ET-trees in O(m + n) time. (Recall that m is the initial number of edges in G.) We initialize As as follows. First, we build the ET-trees and dynamic trees for As 's spanning forest, which requires O(m log n + n) total time [25]. Second, at every internal node of an ET-tree, we store the number of nontree edges incident to all occurrences in its subtree, which takes O(log n) time per nontree edge and O(m log n) time overall. Third, we use the linear time algorithm of Mohar [21] to compute an embedding of As with genus at most g . Thus, initializing As requires O(m log n + n) time. We also build each Ai ; 0 < i < s; by initializing its spanning forest with a copy of As 's spanning forest, but with no nontree edges. Until its rst rebuild, each Ai ; 0 < i < s; has no nontree edges and thus is e ectively empty. The initialization requires O(m log2 n + n log n) total time. 9

Updates Consider an insertion into G. Deciding whether the edge connects di erent trees of F requires O(log n= log log n) time. Inserting the edge into F requires O(log2 n= log log n) time and inserting it into A0 requires O(1) time, not including the time for the rebuilding that results. Consider a deletion from G. Deleting the edge from F and A1 ; : : :; As requires O(log2 n) time, not including the time for updating the Ai 's. Testing the O(log n) candidate edges to nd a replacement edge in G requires O(log2 n= log log n) time. Inserting the chosen edge into F requires O(log2 n= log log n) time and inserting the edges that were not chosen into A0 requires O(log n) time, not including the time for the rebuilding that results. We will charge O(log2 n) to each insertion or deletion in G and analyze the cost of the rebuilding and updating of the Ai 's in the rest of this section. Rebuilding the Ai 's We rebuild an Ai as follows. First, we initialize Ai 's spanning forest with F . We reduce the cost of this initialization by not copying F . Instead, we maintain a list of the deletions made in Ai 's spanning forest since Ai 's last build/rebuild and another list of the changes made in F since Ai 's last build/rebuild. We use these lists to undo the deletions made in Ai 's spanning forest since its last build/rebuild and then to duplicate (in Ai 's spanning forest) the changes made in F since Ai 's last build/rebuild. This makes Ai 's spanning forest identical to F . Since every change in F is subsequently duplicated once in each Ai during some rebuild of Ai , we charge every insertion or deletion in G with the cost of duplicating the resulting change in F (if any) in all the Ai 's. Since each change in an Ai 's spanning forest takes O(log n) time, we charge O(log2 n) to each insertion or deletion in G. Second, we move the nontree edges of Aj ; j < i; into Ai . Since nding a nontree edge of an Aj requires O(log n) time and at most 2i edges are moved, this requires O(2i log n) time. (Since each Aj ; 0 < j < i, no longer has any nontree edges, we may mark Aj as \inactive" until it is rebuilt.) Third, at every internal node of an ET-tree, we store the number of nontree edges incident to all occurrences in its subtree, which takes O(2i log n) time. Lastly, we compute the embedding and face trees for Ai in O(2i log n) time. Thus, rebuilding an Ai requires O(2i log n) time. We will use credits to pay for this cost in advance, as follows. We maintain xi O(log n) credits assigned to each Ai ; i < s. When the algorithm starts, A0 ; : : :; As?1 have no nontree edges and do not require any credits. When Ai is rebuilt, Pxj > 2j for every j < i, which means the sum of the credits assigned to A0 ; : : :; Ai?1 is at least ( j 0.) The algorithm has the following outline. We construct a graph H 0 with the same genus as H and with O(m  ) vertices and edges. We then nd an embedding of H 0 with genus at most g using Mohar's linear time algorithm [21]. Finally, we convert the embedding of H 0 into an embedding of H with genus at most g and build the corresponding face trees. We construct H 0 in three steps. First, we mark certain vertices of T , including the endpoints of H 's nontree edges. Second, we construct a tree T 0 on the marked vertices of T . Third, we add H 's nontree edges to T 0 , which yields H 0.

6.1 First step of the construction

In the rst step, we mark certain vertices of T . Before marking vertices, however, we mark certain occurrences in T 's ET-sequence in two rounds. In round 1, for every nontree edge fu; v g of H , we mark u's designated occurrence and v 's designated occurrence in the ET-sequence. We then reroot T as follows. Choose an arbitrary marked occurrence or and nd r. (We maintain pointers so that given any occurrence ov in an ET-sequence, we can nd its corresponding vertex v in constant time.) Root T at r by using the reroot operation [16] to make or the rst occurrence in T 's ETsequence. Mark the last occurrence in T 's ET-sequence, which is an occurrence of r. Lastly, root T 's dynamic tree at r using the evert operation [25]. Round 1 requires O(m + log n) = O(m log n) time. In round 2, we consider the marked occurrences in the order in which they appear in T 's ETsequence. (We can determine this order by following parent pointers from every marked occurrence to the root of T 's ET-tree.) For every two consecutive marked occurrences ox and oy in T 's ETsequence, do the following. Find z = LCA(x; y ), which is the least common ancestor of x and y in T . Note x 6= y. If z 6= x and z 6= y, nd the rst edge ex (resp. ey ) on the path from z to x (resp. z to y) in T and mark the four occurrences of z incident to the four directed edges corresponding to ex and ey . Otherwise, if z = x (resp. z = y ), nd the rst edge ey (resp. ex ) on the path from 11

z to y (resp. z to x) in T and mark the two occurrences of z incident to the two directed edges corresponding to ey (resp. ex ). Round 2 requires O(m log n) time because nding each LCA(x; y ) and the corresponding edges ex ; ey takes O(log n) time using T 's dynamic tree [25]. Finally, we mark every vertex of T that has

at least one marked occurrence. This completes the rst step of the transformation, which requires O(m log n) time. There are O(m ) marked occurrences and O(m ) marked vertices. (In fact, the algorithm does not require the marked vertices, but we use them to simplify the presentation.) We will use the following de nitions. Let ox ; oy be occurrences. ox < oy if ox precedes oy in T 's ET-sequence. ox and oy are 1-consecutive (resp. 2-consecutive) if ox < oy and at the end of round 1 (resp. round 2), ox and oy are marked but there is no marked oz such that ox < oz < oy . Note 1-consecutive does not imply 2-consecutive and vice-versa. Let u; v be vertices. u covers v if there are marked occurrences o1u ; o2u of u such that o1u < ov < o2u for every occurrence ov of v . Note u covers v only if u is a proper ancestor of v . Lastly, Tv is the subtree of T rooted at v .

Observation 1 Suppose ox and oy are 1-consecutive occurrences and z = LCA(x; y). When ox and oy are considered in round 2, the following results. If z = 6 x and z =6 y and oz < oz  oz < oz are the occurrences marked, then z covers x and y , with oz < o0x < oz  oz < o0y < oz for any 1

1

2

3

2

3

4

4

occurrences o0x ; o0y of x; y . If z = x and o1z < o2z are the occurrences marked, then z covers y , with o1z < o0y < o2z for any occurrence o0y of y. Similarly, if z = y and o1z < o2z are the occurrences marked, then z covers x, with o1z < o0x < o2z for any occurrence o0x of x.

Lemma 5 If ox and oy are 2-consecutive occurrences in T 's ET-sequence, x =6 y, then either (1) x is a proper ancestor of y and x covers y, or (2) y is a proper ancestor of x and y covers x. Proof We will implicitly use Observation 1 throughout the proof. In the rst part of the proof, we

show that x is a proper ancestor of y or vice-versa. Suppose otherwise and let z = LCA(x; y ). Then z 6= x and z 6= y. Since x and y are proper descendants of z and ox < oy , then every occurrence of a vertex in Tx precedes every occurrence of a vertex in Ty . Let ox0 and oy0 be the last and rst occurrence, respectively, such that ox0  ox < oy  oy0 and ox0 ; oy0 were marked in round 1. We show that y 0 2 Ty . If oy was marked in round 1, then oy0 = oy . Otherwise, since oy was marked in round 2, then Ty contains at least two vertices with occurrences marked in round 1 that succeed oy (because ox and oy are 2-consecutive). Thus, y 0 2 Ty . The symmetric argument shows that x0 2 Tx. Since ox and oy are 2-consecutive, then ox0 and oy0 are 1-consecutive. Since x0 2 Tx and y 0 2 Ty , then LCA(x0; y 0) = LCA(x; y ) = z . This means two occurrences of z between ox and oy were marked in round 2, a contradiction. Thus, x is a proper ancestor of y or vice-versa. In the second part of the proof, we show that if x is a proper ancestor of y , then x covers y . (The symmetric argument shows that if y is a proper ancestor of x, then y covers x.) Let T1; : : :; Tk be the subtrees rooted at the children of x and let y 2 Tj ; 1  j  k. (See Figure 1.) Let ox0 be the last occurrence such that ox0  ox and ox0 was marked in round 1. Case 1: x0 2 Tx. Then either x0 = x or x0 2 Ti for some 1  i < j . Let oy0 be the rst occurrence such that oy  oy0 and oy0 was marked in round 1. We claim y 0 2 Ty . Since ox and oy are 2-consecutive, then oy is the rst marked occurrence of a vertex in Ty . Then either oy was marked in round 1, or oy was marked in round 2 and so Ty contains at least two vertices with occurrences marked in round 1 that succeed oy . Thus, y 0 2 Ty . This implies LCA(x0; y 0) = x. Now since ox and oy are 2-consecutive, then ox0 and oy0 are 1-consecutive. Hence, after round 2, x covers y. 12

x

y

T1

Tj

Tk

Figure 1: The subtrees rooted at the children of x. Case 2: x0 62 Tx. Since ox was marked in round 2, then there are 1-consecutive occurrences ou and ov such that ou and ov caused ox to be marked in round 2. Thus, LCA(u; v ) = x. Case 2a: u = x or v = x. Suppose u = x, which means ou is a di erent occurrence of x than ox . (The case v = x is symmetric.) We claim v 2 Tj . If v 2 Ti; i < j , then ov < ox (because ox and oy are 2-consecutive), which implies x0 2 Tx , a contradiction. If v 2 Ti ; i > j , then we must have oy < ox , a contradiction. Thus, v 2 Tj . This means that after round 2, u = x covers v . Since y 2 Tj , then after round 2, x covers y. Case 2b: u 6= x and v 6= x. We claim u 2 Tj . As before, if u 2 Ti; i < j , then x0 2 Tx , a contradiction. If u 2 Ti ; j < i, then v 2 Ti0 ; i < i0, which implies oy < ox , a contradiction. Thus, u 2 Tj . Then after round 2, x covers u. Since y 2 Tj , then after round 2, x covers y. 

6.2 Second step of the construction

In the second step, we construct the tree T 0 on the marked vertices of T . We again consider the marked occurrences in the order in which they appear in T 's ET-sequence. For every two 2consecutive occurrences ox and oy , do the following. Let X be the ET-subsequence (the subsequence of T 's ET-sequence) from ox to oy , including ox and oy . If x 6= y , add the directed edge (x; y ) to T 0 and associate X with (x; y). If x = y, nd the previous directed edge added to T 0 , which has the form (w; x), and extend its associated ET-subsequence to include X . (If x = y and there is no previous directed edge, then we have r = x = y . In this case, extend X to include the next ETsubsequence by setting oy to be the next marked occurrence; we will eventually have r = x 6= y .) Since there are O(m  ) marked occurrences, this step requires O(m  log n) time.

Observation 2 Let Si be the ET-subsequence associated with the ith directed edge added to T 0. (a)

The Si 's are pairwise disjoint except for every consecutive pair Si and Si+1 , which intersect in their last and rst occurrences, respectively. (b) Each Si 's rst and last occurrences ou ; ov are marked and there are no other marked occurrences in Si except possibly for occurrences of u; v . (c) T 's set of directed edges (which is represented by T 's ET-sequence) is partitioned by the Si 's, implying that every directed edge of T is associated with a unique directed edge of T 0 .

Lemma 6 T 0 is the directed version of an undirected tree. Proof Let x; y be any vertices of T 0. We will show that (x; y) is a directed edge of T 0 i (y; x) is a directed edge of T 0 . If x = y , then neither (x; y ) nor (y; x) is a directed edge of T 0. Suppose x 6= y and (x; y) is a directed edge of T 0 . Then there are 2-consecutive occurrences ox and oy in T 's ET-sequence. By Lemma 5, x is a proper ancestor of y in T or vice-versa. 13

We show that if x is a proper ancestor of y in T , then (y; x) is a directed edge of T 0. (The symmetric argument shows that if y is a proper ancestor of x in T , then (y; x) is a directed edge of T 0.) Let o0y be the last marked occurrence of y and let oz be the next marked occurrence after o0y , so that y 6= z. Since x covers y by Lemma 5, there is a marked occurrence o0x of x such that o0y < o0x . Thus, ox < oy  o0y < oz  o0x . Since o0y and oz are 2-consecutive, then by Lemma 5, either y covers z or z covers y . But y cannot cover z because o0y is y 's last marked occurrence and o0y < oz . Thus, z covers y and z is a proper ancestor of y . Since x is also a proper ancestor of y , then x is an ancestor or a descendant of z . By the choice of oz , x must be an ancestor of z . We claim that x = z . Suppose x 6= z . Then x is a proper ancestor of z and z is a proper ancestor of y . (See Figure 2.) Since z covers y , there is a marked occurrence o0z of z such that o0z < oy . Since ox < oy , we must have ox < o0z . Then ox < o0z < oy , a contradiction since ox and oy are 2-consecutive. Thus, x = z, i.e., oz is an occurrence of x. Since o0y and oz are 2-consecutive occurrences in T 's ET-sequence, y 6= x, then (y; x) is a directed edge of T 0 , as required. x

z

y

Figure 2: x is a proper ancestor of z and z is a proper ancestor of y . We have shown T 0 is the directed version of an undirected graph. We now show T 0 is the directed version of an undirected tree. By Observation 2(a), T 0 is connected. Let (x; y ) be any directed edge of T 0. Then x is a proper ancestor of y in T or vice-versa. By Observation 2(b), x and y are marked vertices of T and no internal vertex on the path from x to y in T is marked. Thus, x is the nearest marked proper ancestor of y or vice-versa. Hence, T 0 is acyclic, which proves the lemma.  We will refer to a pair of opposite directed edges of T 0 as an undirected edge. Let Sxy be the ET-subsequence associated with the directed edge (x; y ) of T 0 . Lemma 7 Let fx; yg be an undirected edge of T 0. (a) The directed edges represented by Sxy [ Syx induce a subtree Txy of T . (b) If fu; v g 6= fx; y g is an undirected edge of T 0, then Txy ; Tuv are edgedisjoint and Txy ; Tuv are vertex-disjoint except possibly for x; y; u; v , which satisfy jfx; y g\fu; v gj  1. (c) If T is modi ed by replacing each Txy with (x; y ); (y; x), the resulting tree is T 0. Proof (a) Follows since Sxy (resp. Syx) is a subsequence of T 's ET-sequence that begins with an occurrence of x (resp. y ) and ends with an occurrence of y (resp. x). (b) Follows from Observation 2(a). (c) By Observation 2(c) and parts (a), (b), the edges of the Txy 's form a partition of the edges of T . Thus, modifying T by replacing each Txy with (x; y ); (y; x) yields T 0. 

6.3 Third step of the construction

In the third step, we add H 's nontree edges to T 0. (Recall that the endpoints of H 's nontree edges are vertices of T 0 .) The resulting graph is H 0, which has O(m  ) vertices and edges. By Lemma 6, 14

T 0 is a spanning tree of H 0.

Theorem 8 H and H 0 have the same genus. Proof Let  be any embedding of H . We will transform H into H 0 and  into an embedding 0 of

H 0 such that  and 0 have the same genus. We de ne a sequence of graphs H = H0; H1; : : :; Hk = H 0 with a corresponding sequence of embeddings  = 0 ; 1; : : :; k = 0 , where k is the number of undirected edges in T 0 . We obtain Hi from Hi?1 by replacing Txy with (x; y ); (y; x), where fx; y g is the ith undirected edge of T 0. By Lemma 7, Hk = H 0. It only remains to show how to transform

i?1 into i such that i?1 and i have the same genus. Consider Hi?1 . Let fx; y g be the ith undirected edge of T 0 and let x be an ancestor of y in T . Since no vertex of Txy is marked unless it is x or y (by Observation 2), then no vertex of Txy is incident to a nontree edge unless it is x or y . This implies, as we show next, that there are two faces f1 ; f2 of i?1 such that every edge of Txy is in f1 [ f2 . Let P be the path in Txy between x and y . Let e = fu; v g be any edge of Txy such that u 2 P; v 62 P , i.e., e is incident to P but e is not in P . Let Te be the tree e [ Tv . (Informally, Te is a tree \hanging o " P .) Then Tv is a subtree of Txy and no vertex of Tv is marked, implying that no vertex of Tv is incident to a nontree edge of H . Thus, if face f contains (u; v ), then f contains every directed edge of Te , for any embedding of Hi?1 . Consequently, since every edge of P is contained in at most two faces, there are two (not necessarily distinct) faces f1 ; f2 of i?1 , such that every edge of Txy is in f1 [ f2 . Furthermore, we can change (if necessary) the cyclic permutations of P 's vertices in i?1 so that f1 and f2 contain the directed edges of Sxy and Syx , respectively. Since the changed embedding 0i?1 has the same number of faces as i?1 , then 0i?1 and i?1 have the same genus. (Recall that Euler's formula for connected graphs is m ? n ? f = 2(g ? 1), where f is the number of faces and g is the genus.) Now consider Hi , which is obtained from Hi?1 by replacing Txy with (x; y ) and (y; x). We obtain i from 0i?1 in the appropriate way, i.e., the sequence of directed edges Sxy (resp. Syx ) in f1 (resp. f2 ) is replaced by (x; y ) (resp. (y; x)). We compute the genus of i as follows. The number of faces of i and 0i?1 is the same, but the number of vertices and edges in Hi and Hi?1 is di erent: the tree Txy with l vertices and l ? 1 edges was replaced by one undirected edge, which is a tree with 2 vertices and 1 edge. By Euler's formula, i and 0i?1 have the same genus, which implies i and i?1 have the same genus. It is straightforward to show that given H 0 with an embedding 0 , the reverse process transforms 0 H into H and 0 into an embedding  of H such that 0 and  have the same genus. Hence, H and H 0 have the same genus. 

6.4 Computing an embedding of H

We now use the linear time algorithm of Mohar [21] to compute an embedding of H 0 with genus at most g . If Mohar's algorithm fails to nd such an embedding, then Theorem 8 implies that the genus of H is greater than g . (However, our connected components algorithm assumes the genus of G | and therefore H | is at most g.) Given an embedding of H 0, we compute its faces (without face trees) by traversing H 0 in O(m  ) time. We compute the faces and face trees for H as follows. For every directed edge (x; y ) in a face of H 0, if (x; y ) is an edge of T 0 , we replace (x; y ) with its associated ET-subsequence Sxy . Since T 's ET-sequence is stored in a degree-2 ET-tree, we can splice out Sxy from T 's ET-sequence in O(log n) time. We must also add the common occurrence between consecutive Si ; Si+1 pairs, which also takes O(log n) time. Since T 0 has O(m ) edges, there 15

are O(m  ) ET-subsequences to splice out. We construct the face trees for H by concatenating the ET-subsequences of each face of H 0, which takes O(m log n) time. By the argument given in the proof of Theorem 8, the embedding for H has genus at most g . In our connected components algorithm, H is a connected component of some Ai . We therefore maintain two copies of the ET-trees for Ai 's local forest, one for the deletions-only data structure and one for the embedding algorithm, which is called when Ai is built or rebuilt. When the embedding algorithm is called, we restore the second ET-tree by undoing the deletions and undoing the splices and concatenations in the previous call of the embedding algorithm. This restores the second ETtree for the current call of the embedding algorithm. Thus, when an Ai is rebuilt, we can nd an embedding of Ai with genus at most g and build the corresponding face trees in O(m  log n) time.

Acknowledgement

The authors thank Wendy Myrvold for pointing out reference [21].

References [1] G. Di Battista and R. Tamassia. On-line planarity testing. SIAM Journal on Computing, 25(5):956{997, 1996. [2] M. Behzad, G. Chartrand, and L. Lesniak-Foster. Graphs and Digraphs. Prindle, Weber and Schmidt, Boston, MA, 1979. [3] F. Chin and D. Houck. Algorithms for updating spanning trees. Journal of Computer and System Sciences, 16:333{344, 1978. [4] T. H. Cormen, C. E. Leiserson, and R. L. Rivest. Introduction to Algorithms. MIT Press and McGraw-Hill Book Co., Cambridge, MA and New York, NY, 1990. [5] J. Edmonds. A combinatorial representation for polyhedral surfaces. Notices of the American Mathematical Society, 7:646, 1960. [6] D. Eppstein, Z. Galil, and G. F. Italiano. Improved sparsi cation. Technical Report 93-20, Dept. of Information and Computer Science, University of California at Irvine, 1993. [7] D. Eppstein, Z. Galil, G. F. Italiano, and A. Nissenzweig. Sparsi cation | a technique for speeding up dynamic graph algorithms. In Proceedings of the 33rd Symposium on Foundations of Computer Science, pages 60{69, 1992. [8] D. Eppstein, Z. Galil, G. F. Italiano, and T. H. Spencer. Separator based sparsi cation I. Planarity testing and minimum spanning trees. Journal of Computer and System Sciences, 52:3{27, 1996. [9] D. Eppstein, G. F. Italiano, R. Tamassia, R. E. Tarjan, J. Westbrook, and M. Yung. Maintenance of a minimum spanning forest in a dynamic plane graph. Journal of Algorithms, 13:33{54, 1992. [10] S. Even and Y. Shiloach. An on-line edge-deletion problem. Journal of the ACM, 28(1):1{4, 1981. [11] J. Feigenbaum and S. Kannan. Dynamic graph algorithms. In Rosen, editor, Handbook of Discrete and Combinatorial Mathematics, chapter 17. CRC Press, Boca Raton, FL. To appear. 16

[12] I. Filotti, G. Miller, and J. Reif. On determining the genus of a graph in O(v O (g )) steps. In Proceedings of the 11th Annual ACM Symposium on the Theory of Computing, pages 27{37, 1979. [13] G. N. Frederickson. Data structures for on-line updating of minimum spanning trees, with applications. SIAM Journal on Computing, 14(4):781{798, 1985. [14] G. N. Frederickson. Ambivalent data structures for dynamic 2-edge-connectivity and k smallest spanning trees. SIAM Journal on Computing, 26(2):484{538, 1997. [15] M. R. Henzinger and V. King. Fully dynamic biconnectivity and transitive closure. In Proceedings of the 36th Annual Symposium on Foundations of Computer Science, pages 664{672, 1995. [16] M. R. Henzinger and V. King. Randomized dynamic graph algorithms with polylogarithmic time per operation. In Proceedings of the 27th Annual ACM Symposium on the Theory of Computing, pages 519{527, 1995. To appear in Journal of the ACM. [17] M. R. Henzinger and V. King. Maintaining minimum spanning trees in dynamic graphs. In Proceedings of the 24th ICALP, LNCS 1256, pages 594{604. Springer-Verlag, 1997. [18] M. R. Henzinger and M. Thorup. Improved sampling with applications to dynamic graph algorithms. In Proceedings of the 23rd ICALP, LNCS 1099, pages 290{299. Springer-Verlag, 1996. [19] J. Hershberger, M. Rauch, and S. Suri. Data structures for two-edge connectivity in planar graphs. Theoretical Computer Science, 130:139{161, 1994. [20] G. F. Italiano, J. A. La Poutre, and M. H. Rauch. Fully dynamic planarity testing in planar embedded graphs. In European Symposium on Algorithms '93, LNCS 726, pages 212{223. Springer-Verlag, 1993. [21] B. Mohar. Embedding graphs in an arbitrary surface in linear time. In Proceedings of the 28th Annual ACM Symposium on the Theory of Computing, pages 392{397, 1996. To appear in SIAM J. Discrete Mathematics. [22] H. Nagamochi and T. Ibaraki. Linear time algorithms for nding a sparse k-connected spanning subgraph of a k-connected graph. Algorithmica, 7:583{596, 1992. [23] M. Rauch. Improved data structures for fully dynamic biconnectivity. In Proceedings of the 26th Annual ACM Symposium on the Theory of Computing, pages 686{695, 1994. [24] J. H. Reif. A topological approach to dynamic graph connectivity. Information Processing Letters, 25:65{70, 1987. [25] D. D. Sleator and R. E. Tarjan. A data structure for dynamic trees. Journal of Computer and System Sciences, 26:362{391, 1983. [26] P. M. Spira and A. Pan. On nding and updating spanning trees and shortest paths. SIAM Journal on Computing, 4(3):375{380, 1975. 17

[27] R. E. Tarjan. Eciency of a good but not linear set union algorithm. Journal of the ACM, 22(2):215{225, 1975. [28] C. Thomassen. The graph genus problem is NP-complete. J. Algorithms, 10:568{576, 1989. [29] C. Thomassen. Embeddings of graphs. Discrete Mathematics, 124:217{228, 1994. [30] A. White. Graphs, Groups and Surfaces. North-Holland/American Elsevier, Amsterdam/New York, 1973.

18

Suggest Documents