adjacency queries in dynamic sparse graphs

5
Information Processing Letters 102 (2007) 191–195 www.elsevier.com/locate/ipl Adjacency queries in dynamic sparse graphs Lukasz Kowalik 1 Institute of Informatics, Warsaw University,Banacha 2, 02-097 Warsaw, Poland Received 25 April 2006; received in revised form 6 December 2006; accepted 6 December 2006 Available online 19 December 2006 Communicated by K. Iwama Abstract We deal with the problem of maintaining a dynamic graph so that queries of the form “is there an edge between u and v?” are processed fast. We consider graphs of bounded arboricity, i.e., graphs with no dense subgraphs, like, for example, planar graphs. Brodal and Fagerberg [G.S. Brodal, R. Fagerberg, Dynamic representations of sparse graphs, in: Proc. 6th Internat. Workshop on Algorithms and Data Structures (WADS’99), in: Lecture Notes in Comput. Sci., vol. 1663, Springer, Berlin, 1999, pp. 342–351] described a very simple linear-size data structure which processes queries in constant worst-case time and performs insertions and deletions in O(1) and O(log n) amortized time, respectively. We show a complementary result that their data structure can be used to get O(log n) worst-case time for query, O(1) amortized time for insertions and O(1) worst-case time for deletions. Moreover, our analysis shows that by combining the data structure of Brodal and Fagerberg with efficient dictionaries one gets O(log log log n) worst-case time bound for queries and deletions and O(log log log n) amortized time for insertions, with size of the data structure still linear. This last result holds even for graphs of arboricity bounded by O(log k n), for some constant k. © 2006 Elsevier B.V. All rights reserved. Keywords: Data structures; Graph algorithms; Adjacency; Orientation; Dynamic 1. Introduction In the present paper we study fully dynamic graphs, i.e., graphs which change in time by means of insert- ing and removing edges (it is straightforward to extend our results for the situation when also vertices may be inserted and removed). Such a setting raises a natural question: how to store the structure of the graph in mem- ory so that some kind of information can be retrieved fast. More specifically, we focus on the most basic sort E-mail address: [email protected] (L. Kowalik). 1 This work was partially done when the author was a postdoc in Max-Planck-Institut für Informatik, Saarbrücken, Germany. Sup- ported in part by KBN grant 4T11C04425. of information about graph: adjacency. In other words, we allow for processing queries of the form Are vertices u and v adjacent?. When the graph under consideration is dense, e.g., it has (n 2 ) edges 2 there is a trivial and efficient solution: store an adjacency matrix. Then both the updates and the queries take constant time. How- ever, for big sparse graphs, like planar graphs, such the approach may be considered as unacceptable because of huge memory requirements compared to the actual size of the graph stored. Hence, we consider only data structures of linear space complexity. Then one can use another classic data structure: adjacency lists. Unfortu- 2 Throughout the paper n and m denote the number of vertices and edges, respectively. 0020-0190/$ – see front matter © 2006 Elsevier B.V. All rights reserved. doi:10.1016/j.ipl.2006.12.006

Upload: lukasz-kowalik

Post on 26-Jun-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Adjacency queries in dynamic sparse graphs

Information Processing Letters 102 (2007) 191–195

www.elsevier.com/locate/ipl

Adjacency queries in dynamic sparse graphs

Łukasz Kowalik 1

Institute of Informatics, Warsaw University, Banacha 2, 02-097 Warsaw, Poland

Received 25 April 2006; received in revised form 6 December 2006; accepted 6 December 2006

Available online 19 December 2006

Communicated by K. Iwama

Abstract

We deal with the problem of maintaining a dynamic graph so that queries of the form “is there an edge between u and v?” areprocessed fast. We consider graphs of bounded arboricity, i.e., graphs with no dense subgraphs, like, for example, planar graphs.Brodal and Fagerberg [G.S. Brodal, R. Fagerberg, Dynamic representations of sparse graphs, in: Proc. 6th Internat. Workshop onAlgorithms and Data Structures (WADS’99), in: Lecture Notes in Comput. Sci., vol. 1663, Springer, Berlin, 1999, pp. 342–351]described a very simple linear-size data structure which processes queries in constant worst-case time and performs insertions anddeletions in O(1) and O(logn) amortized time, respectively. We show a complementary result that their data structure can be usedto get O(logn) worst-case time for query, O(1) amortized time for insertions and O(1) worst-case time for deletions. Moreover, ouranalysis shows that by combining the data structure of Brodal and Fagerberg with efficient dictionaries one gets O(log log logn)

worst-case time bound for queries and deletions and O(log log logn) amortized time for insertions, with size of the data structurestill linear. This last result holds even for graphs of arboricity bounded by O(logk n), for some constant k.© 2006 Elsevier B.V. All rights reserved.

Keywords: Data structures; Graph algorithms; Adjacency; Orientation; Dynamic

1. Introduction

In the present paper we study fully dynamic graphs,i.e., graphs which change in time by means of insert-ing and removing edges (it is straightforward to extendour results for the situation when also vertices may beinserted and removed). Such a setting raises a naturalquestion: how to store the structure of the graph in mem-ory so that some kind of information can be retrievedfast. More specifically, we focus on the most basic sort

E-mail address: [email protected] (Ł. Kowalik).1 This work was partially done when the author was a postdoc

in Max-Planck-Institut für Informatik, Saarbrücken, Germany. Sup-ported in part by KBN grant 4T11C04425.

0020-0190/$ – see front matter © 2006 Elsevier B.V. All rights reserved.doi:10.1016/j.ipl.2006.12.006

of information about graph: adjacency. In other words,we allow for processing queries of the form Are verticesu and v adjacent?. When the graph under considerationis dense, e.g., it has �(n2) edges2 there is a trivial andefficient solution: store an adjacency matrix. Then boththe updates and the queries take constant time. How-ever, for big sparse graphs, like planar graphs, such theapproach may be considered as unacceptable becauseof huge memory requirements compared to the actualsize of the graph stored. Hence, we consider only datastructures of linear space complexity. Then one can useanother classic data structure: adjacency lists. Unfortu-

2 Throughout the paper n and m denote the number of vertices andedges, respectively.

Page 2: Adjacency queries in dynamic sparse graphs

192 Ł. Kowalik / Information Processing Letters 102 (2007) 191–195

nately, in this case time needed to process a query maybe too large, unless there is some bound on the vertices’degrees in the graph. In order to fix that problem in thecase of planar graphs, Chrobak and Eppstein [5] usedthe fact that edges of an undirected planar graph can beoriented so that at most 3 edges leave every vertex. Theynoticed that it suffices to store the adjacency lists of theresulting directed graph—then u and v are adjacent inthe original graph if and only if u is in the adjacencylist of v or vice versa. However, Chrobak and Eppsteinconsidered only static graphs.

The dynamic case was studied by Brodal and Fager-berg [4]. They consider more general class than planargraphs—graphs with arboricity bounded by some con-stant c. Arboricity of graph G, denoted as arb(G), isthe smallest number of forests needed to cover all edgesof G. A theorem by Nash-Williams [13] says that ar-boricity is equal to maxJ �|E(J )|/(|V (J )| − 1)� whereJ is any subgraph of G with |V (J )| � 2 vertices and|E(J )| edges. Intuitively, graphs of bounded arboric-ity are uniformly sparse, i.e., they do not have densesubgraphs. (In particular, planar graphs have arboric-ity 3.) Brodal and Fagerberg show how to maintain abounded outdegree orientation of such graphs. Clearlythis allows for processing adjacency queries in constanttime. They show that their update algorithm is asymp-totically optimal (see Section 2 for details). However,tight time complexity analysis of their approach still re-mains open. The authors were able to show that whenorientation with outdegree Δ is maintained, Δ � 4c, theamortized time per operation is constant for insertionsand O(logn) for deletions. Another analysis gives O(1)

worst-case deletion time and O(logn) amortized inser-tion time. These results have applications in boundedlength shortest path oracles [10] and, more surprisingly,graph coloring [9].

Our results. In this paper we extend the work of Bro-dal and Fagerberg [4] by using a slightly different ap-proach. Instead of maintaining outdegrees in the ori-entation bounded by a constant and trying to reducethe update time, we ask how one can bound the out-degrees, while the amortized update time is constant.However, since the algorithm of Brodal and Fagerbergis asymptotically optimal, there is no need for design-ing a new one. We show that when their algorithmis supposed to maintain orientation with outdegree Δ,for Δ � 4c(�log cn� + 1), insertions take O(1) amor-tized time and deletions O(1) worst-case time (recallthat c is the bound on arboricity). Clearly, this allowsfor processing adjacency queries in O(logn) worst-casetime when the arboricity is bounded. Note that in the

applications in which we are interested in the total timeof the whole sequence of operations, like, for example,when the orientation is used as a data structure in somealgorithm, this is optimal when the updates are frequentcompared to queries, i.e., the ratio of number of updatesto the number of queries is �(logn).

Dictionary approach. Another natural approach to ourproblem is storing the information about the edges ofthe dynamic graph in a dictionary, i.e., a data structurewhich enables adding, removing and finding keys (el-ements). In our case these elements are edges of thegraph. For convenience, we will assume that vertices ofthe graph are enumerated from 1 to n and that a pair ofvertices describing an edge can be stored in one word ofmemory (it is common in analysis of graph algorithmsto assume that each vertex can be stored in O(1) wordsof memory).

Dietzfelbinger et al. [6] show a linear-size random-ized dictionary based on hashing with O(1) worst-casetime lookups and O(1) amortized expected time up-dates.

Without randomization the dynamic dictionary prob-lem seems to be harder: Mehlhorn et al. [11] showthat �(m log logm) time is needed for m insertionsin some deterministic model of linear-space dictionarythat encompasses both hashing strategies and searchtrees, which are the two most efficient solutions tothe dictionary problem. However, in our case, whenthe size of the universe (number of possible edges) israther small, there is a solution very close to this lowerbound. Namely, the dynamization technique by Ander-sson and Thorup [2] applied to the exponential searchtrees by Beame and Fich [3], achieves the O(log logm ·(log logU)/log log logU) worst-case time bound forboth lookups and updates, where m is the number ofkeys stored and U is the maximal key stored in dictio-nary (it is assumed that the dictionary stores integers).Note that in the case of storing edges U � n2, whichgives us a bound of O((log logn)2/log log logn) on theworst-time complexity of each operation.

Our results combined with dictionary approach. Themain asset of our result is simplicity of the algorithmwith its asymptotic optimality in situations when the up-dates are very frequent. However, by combining our ap-proach with deterministic dictionaries one obtains the-oretically extremely efficient solution: O(log log logn)

worst-case time for query and edge deletion andO(log log logn) amortized time for insertion, whenthe dynamic graph under consideration has arboricitybounded by O(logk n), for some constant k. Hence we

Page 3: Adjacency queries in dynamic sparse graphs

Ł. Kowalik / Information Processing Letters 102 (2007) 191–195 193

get the best known deterministic method for storing ad-jacency of sparse graphs in the situation when queriesand updates appear similarly often. This should be com-pared with the already mentioned �(log logn) lowerbound [11] for amortized insertion time in the dynamicdeterministic dictionary which stores all the edges ofthe graph.

Adjacency labeling schemes. Kannan et al. [8] intro-duced the idea of a labeling scheme, where each vertexof a graph is assigned a label so that adjacency of twovertices can be decided based only on their labels. Wenote that having an orientation of a graph G one getsa labeling scheme for G in which the label of a ver-tex v is the number of v together with the numbers ofendvertices of the edges leaving v. It follows that theperformance bounds from both the paper of Brodal andFagerberg and the present paper may be reformulated asthe relevant space and time bounds for dynamic labelingscheme in graphs of bounded arboricity. The problem ofmaintaining dynamic adjacency labels was also consid-ered recently by Morgan [12], who focused on the caseof line graphs.

Comparison. The above discussion shows that thereare two leading approaches for the problem of maintain-ing adjacency of a dynamic graph of bounded arboric-ity: randomized dynamic hashing and bounded outde-gree orientations. We point out the following assets ofthe orientation approach:

• deterministic algorithm,• the information is distributed evenly over the nodes

of the graph (labeling scheme).

2. The algorithm of Brodal and Fagerberg

In this section we sketch the approach from the pa-per [4]. We will use the following notions. Orientationof an undirected graph G is a directed graph �G obtainedfrom G by replacing each edge, say uv, either by arc(u, v) or by arc (v,u). We will also say that �G is ad-orientation when the outdegree of every vertex doesnot exceed d . Let �G1, �G2, . . . , �Gt be a sequence of ori-entations. We say that edge uv is reoriented in graphGi when uv has different orientations in Gi−1 and Gi .Each such pair (uv, i) is called a reorientation. How-ever, the term reorientation with respect to an algorithmwill mean simply an operation of reversing the orienta-tion of an edge.

The algorithm of Brodal and Fagerberg works as fol-lows. Let Δ be the bound on vertices’ outdegrees thathas to be maintained. Then when an edge is removed

from the graph the algorithm simply removes its ori-ented counterpart. After adding an edge the algorithmorients it arbitrarily. Next, as long as the orientation con-tains a vertex of outdegree larger than Δ such a vertexx is picked and the orientation of all the edges leavingx is reversed.

Clearly, the total time used by the above algorithm tomaintain Δ-orientation during a sequence of updates islinear in the length of the sequence added to the num-ber of reorientations performed. The following lemmastates that the above algorithm is asymptotically optimalwith respect to the number of reorientations performed.It follows that it is also optimal in running time sinceits time complexity is linear in the number of reorienta-tions and any algorithm which maintains orientation hasto make reorientations.

Lemma 2.1. (Brodal and Fagerberg [4]) Let σ be a se-quence of insertions and deletions on an initially emptygraph. Let Gi be the graph after ith operation and let k

denote the number of edge insertions.If there exists a sequence �G0, �G1, . . . , �G|σ | of δ-ori-

entations with at most r edge reorientations in total,then the algorithm performs at most

(k + r)Δ + 1

Δ + 1 − 2δ

edge reorientations in total on the sequence σ , providedΔ � 2δ.

3. Analysis for logarithmic outdegrees

Lemma 2.1 implies that in order to bound the amor-tized time of insert operations in Brodal–Fagerberg al-gorithm it suffices to construct for an arbitrary sequenceof edge deletions and insertions, a sequence of orien-tations of the relevant graphs with a small number ofedge reorientations. However, in what follows we showthat when the bound on outdegree is logarithmic in thelength of the sequence, then there exists a sequence oforientations with no single reorientation.

Lemma 3.1. Any graph with arboricity c can be c-ori-ented.

Proof. The orientation can be found by decomposingthe graph into c forests, choosing a root in each tree andorienting edges of each tree towards its root. �Lemma 3.2. Let G1, . . . ,Gt be any sequence of graphswith arboricity bounded by c. Then there exists a se-quence �G1, . . . , �Gt of c(�log t� + 1)-orientations withno edge reorientations.

Page 4: Adjacency queries in dynamic sparse graphs

194 Ł. Kowalik / Information Processing Letters 102 (2007) 191–195

Proof. The proof is by the induction on t . For t = 1 thelemma is equivalent to Lemma 3.1. Now assume t > 1and let k = �t/2�. Let �G′

1, . . . ,�G′

k be a sequence ofc(�logk� + 1)-orientations of graphs G1, . . . ,Gk withno reorientations, which exists by the induction hy-pothesis. Similarly, when k + 2 � t , from the induc-tion hypothesis we get �G′

k+2, . . . ,�G′

t —a sequence ofc(�logk�+1)-orientations of graphs Gk+2, . . . ,Gt withno reorientations.

We set �Gk+1 to be a c-orientation of graph Gk+1obtained by Lemma 3.1. Now consider any i �= k + 1and an edge uv ∈ Gi . If uv ∈ Gk+1, we orient uv in�Gi the same as in �Gk+1. Otherwise we orient uv in�Gi the same as in �G′

i . Clearly, for any vertex v ∈ �Gi

we have outdeg �Gi(v) � outdeg �G′

i(v)+outdeg �Gk+1

(v) �c(�logk�+1)+ c � c(�log t�+1). Finally, we considerany edge uv which is present in two successive graphsGi , Gi+1 and we will show that its orientation is thesame. If uv ∈ Gk+1 the orientation of uv in both �Gi and�Gi+1 is the same as in �Gk+1. Otherwise, the orienta-tions of uv in �Gi and �Gi+1 are the same as in �G′

i and�G′

i+1, hence they are the same. �In the following lemma we show that when one al-

lows reorientations, the bound on outdegrees becomesindependent from the length of the sequence.

Lemma 3.3. Let G1, . . . ,Gt be any sequence of graphswith arboricity bounded by c and let α be any in-teger. Then there exists a sequence �G1, . . . , �Gt ofc(�logαn� + 1)-orientations with at most ct/α reori-entations.

Proof. We partition the sequence G1, . . . ,Gt intoblocks of length αn. For each i = 0, . . . , �t/(αn)�graphs in block Giαn+1,Giαn+2, . . . ,G(i+1)αn arec(�logαn� + 1)-oriented using Lemma 3.2. Clearly, re-orientations may appear only immediately after the endof a block, i.e., in graphs �Giαn+1 for i > 0. Since thereare �t/(αn)� such graphs and each of them contains atmost c(n − 1) edges, hence the total number of reorien-tations does not exceed ct/α. �Corollary 3.4. Consider a sequence of edge insertionsand deletions performed on an initially empty graphsuch that after each operation the resulting graph hasarboricity bounded by c. Let k be the number of in-sertions and let α be an integer. When the algorithmof Brodal and Fagerberg is set to maintain orientationwith outdegree at most Δ = 4c(�logαn�+1) then it per-forms at most 2(k + 2kc/α) edge reorientations.

Proof. Since the number of deletions does not exceedthe number of insertions, the sequence of operations haslength at most 2k. Then the corollary follows immedi-ately from Lemmas 2.1 and 3.3. �

By setting α equal to the bound on arboricity c weget the following theorem.

Theorem 3.5. The algorithm of Brodal and Fager-berg can maintain O(c logn)-orientation of an initiallyempty dynamic graph with arboricity bounded by c withconstant amortized insertion time and constant worst-case deletion time.

4. Applying deterministic dictionaries

In the previous section we analyzed the time com-plexity of the algorithm of Brodal and Fagerberg main-taining O(c logn)-orientation of a dynamic graph witharboricity bounded by c. Now consider an implementa-tion of this algorithm, in which for each vertex v thereis a separate dictionary storing the ends of the edgesleaving v. Moreover, let the bound on arboricity bec = O(logk n), for some constant k. Theorem 3.5 im-plies that each dictionary stores O(logk+1 n) keys andeach edge insertion causes amortized constant numberof dictionary insertions and worst-case constant numberof dictionary deletions (namely 2).

In order to get the best bounds, we will use the dictio-nary obtained by applying the dynamization techniqueby Andersson and Thorup [2] to fusion trees by Ander-sson [1] and Fredman and Willard [7]. Let ω denote thememory word length (in bits) and #keys be the numberof keys stored. Then, as stated in [2], this dictionary per-forms both the lookups and updates in worst-case timeO(log log #keys + log #keys/logω). Since in our case theword length is ω = O(logn) and #keys = O(logk+1 n),we get the bound of O(log log logn) for all the threeoperations performed on a single dictionary. This givesus O(log log logn) worst-case time for query and edgedeletion and O(log log logn) amortized time for inser-tion.

Finally, we note that in practical situations it maybe sufficient to use dictionaries which are simpler andeasier in implementation, like splay trees for whichwe get O(log logn) amortized time bounds. Similarly,when one considers weaker model than the word RAM,red-black trees can be used as dictionaries, givingO(log logn) worst-case time for query and edge dele-tion and O(log logn) amortized time for insertion.

Page 5: Adjacency queries in dynamic sparse graphs

Ł. Kowalik / Information Processing Letters 102 (2007) 191–195 195

References

[1] A. Andersson, Faster deterministic sorting and searching in lin-ear space, in: Proc. of the 37th Annual Symposium on Founda-tions of Computer Science (FOCS’96), 1996, pp. 135–141.

[2] A. Andersson, M. Thorup, Tight(er) worst-case bounds on dy-namic searching and priority queues, in: Proc. of the 32nd An-nual ACM Symposium on Theory of Computing (STOC’00),ACM Press, 2000, pp. 335–342.

[3] P. Beame, F.F. Fich, Optimal bounds for the predecessor problemand related problems, J. Comput. System Sci. 65 (2002) 38–72.

[4] G.S. Brodal, R. Fagerberg, Dynamic representations of sparsegraphs, in: Proc. 6th Internat. Workshop on Algorithms andData Structures (WADS’99), in: Lecture Notes in Comput. Sci.,vol. 1663, Springer, Berlin, 1999, pp. 342–351.

[5] M. Chrobak, D. Eppstein, Planar orientations with low out-degree and compaction of adjacency matrices, Theoret. Comput.Sci. 86 (2) (1991) 243–266.

[6] M. Dietzfelbinger, A. Karlin, K. Mehlhorn, F. Meyer auf derHeide, Dynamic perfect hashing: Upper and lower bounds,SIAM J. Comput. 23 (4) (1994) 738–761.

[7] M.L. Fredman, D.E. Willard, Surpassing the information theo-retic bound with fusion trees, J. Comput. System Sci. 47 (1993)424–436.

[8] S. Kannan, M. Naor, S. Rudich, Implicit representation ofgraphs, in: Proc. of the 20th Annual ACM Symposium on The-ory of Computing (STOC’88), New York, NY, USA, ACM Press,1988, pp. 334–343.

[9] Ł. Kowalik, Fast 3-coloring triangle-free planar graphs, in: S. Al-bers, T. Radzik (Eds.), Proc. 12th Annual European Symposiumon Algorithms (ESA 2004), in: Lecture Notes in Comput. Sci.,vol. 3221, Springer-Verlag, Berlin, 2004, pp. 436–447.

[10] Ł. Kowalik, M. Kurowski, Oracles for bounded length shortestpaths in planar graphs, ACM Trans. Algorithms 2 (3) (2006)335–363.

[11] K. Mehlhorn, S. Näher, M. Rauch, On the complexity of a gamerelated to the dictionary problem, SIAM J. Comput. 19 (5) (1990)902–906.

[12] D. Morgan, A dynamic implicit adjacency labeling scheme forline graphs, in: Proc. 9th Int. Workshop on Algorithms andData Structures (WADS’05), in: Lecture Notes in Comput. Sci.,vol. 3608, Springer, Berlin, 2005, pp. 294–305.

[13] C.S.J.A. Nash-Williams, Decomposition of finite graphs intoforests, J. London Math. Soc. 39 (1964) 12.