Incremental Topological Sort and Cycle Detection In˜O(M √ N)

Incremental Topological Sort and Cycle Detection In˜O(M √ N)

p Incremental Topological Sort and Cycle Detection in O~(m n) Expected Total Time Aaron Bernstein ∗ Shiri Chechiky Abstract incremental and the decremental setting, it is often In the incremental cycle detection problem edges are convenient to consider the total update time, that is, the inserted to a directed graph (initially empty) and the aggregate sum of update times over the entire sequence algorithm has to report once a directed cycle is formed of insertions or deletions. in the graph. A closely related problem to the incremen- Dynamic graph algorithms have been the subject of tal cycle detection is that of the incremental topological an extensive study since the late 70's with many papers sort problem, in which edges are inserted to an acyclic cover different aspects and problems of this setting. graph and the algorithm has to maintain a valid topo- Many of the very basic dynamic graph algorithms in logical sort on the vertices at all times. undirected graphs admit by-now near optimal solutions Both incremental cycle detection and incremental (see e.g. [10, 11, 12, 23, 24, 14, 9]). However, dealing topological sort have a long history. The state of with the directed case seems more challenging and in the art is a recent breakthrough of Bender, Fineman, many of the fundamental problems for the directed case Gilbert and Tarjan [TALG 2016], with two different we are still far from seeing the full picture. In this paper algorithms with respective total update times of O~(n2) we consider two fundamental dynamic graph problems and O(m · minfm1=2; n2=3g). The two algorithms work on directed graphs, the incremental cycle detection for both incremental cycle detection and incremental and the incremental topological sort problems. In the topological sort. incremental cycle detection problem we are given a In this paper we introduce a novel technique that directed acyclic graph, and edges are added to the graph allows us to improve upon the state of the art for a one at a time; the algorithm then has to report the first time a directed cycle is formed in the graph. A closely wide range of graph sparsity. Ourp algorithms has a total expected update time of O~(m n) for both the related problem to the incremental cycle detection is incremental cycle detection and the topological sort that of the incremental topological sort problem. Here problems. we are given a directed acyclic graph with edges added one a time, with the additional guarantee that the 1 Introduction graph remains acyclic at all times; the algorithm has to maintain a valid topological sort on the vertices at In dynamic graph algorithms our goal is to maintain all times. some key functionality of a given graph while an ad- The problems of detecting a cycle and maintain- versary keeps changing the graph. In other words, the ing topological sort arise naturally in applications for algorithm needs to handle an online sequence of update scheduling tasks where some tasks must perform before operations, where each update operation involves an in- others. Abstractly, the tasks and constraints are repre- sertion/deletion of an edge of the graph. We say that a sented by a directed graph, where every node is a task dynamic algorithm is decremental if it handles only dele- and an edge between two tasks represents a constraint tions, incremental if handles only insertions and fully that one task must be performed before the other. dynamic if it handles both deletions and insertions. In the static regime, for a given graph G, one can A key objective in dynamic graph algorithms is find either a cycle or a topological order in O(n + m) to minimize the update time, the time it takes the time 1 [17, 20, 22]. Hence, the naive approach in which algorithm to adapt to a change in the graph. In the after every update we simply recompute everything from scratch yields a O(nm + m2) total update time. ∗Technical University of Berlin, Germany. Supported by the The problems of the incremental cycle detection Einstein Grant at TU Berlin. [email protected] yTel Aviv University, Israel. Supported by the Israel Sci- ence Foundation grant No. 1528/15 and the Blavatnik Fund. 1As usual, n (respectively, m) is the number of nodes (resp., [email protected] edges) in the graph. and topological order have been extensively studied in defined with respect to the current graph G. We let the last three decades [3, 19, 21, 15, 18, 2, 1, 16, 8, A(u) denote the set of ancestors of u in G. Analogously, 4, 5, 6]. Marchetti-Spaccamela et al. [19] obtained if there is a path from u to v then we say that v is algorithms for these problems in O(nm) total update a descendant of u, and we let D(u) denote the set of time. Katriel and Bodlaender [15] later gave algorithms descendants of u in G. We say that u is both an ancestor with improved bounds of O(minfm3=2 log n; m3=2 + and a descendant of itself. We say that two vertices u n2 log ng). Afterward, Liu and Chao [18] improved and v are related if one is the ancestor of the other. the bound to O(m3=2 + mn1=2 log n), and Kavitha and We rely on the following existing result about Mathew [16] gave another algorithm with a total update incremental reachability in directed acyclic graphs. time bound of O(m3=2 +nm1=2 log n). See [8] for further discussion on these problems. Lemma 1.1 [13] Given any vertex v, there exists an Recently, Haeupler et al. [8] presented among other algorithm that maintains A(v) and D(v) in total time results an elegant algorithm for these problems with O(m) over the entire sequence of edge insertions. O(m3=2) total update time. In a breakthrough result Note that the average vertex degree in G is Bender, Fineman, Gilbert and Tarjan [5] presented final 2m=n. Our analysis requires that no vertex has degree two different algorithms, with total update time of 2 1=2 2=3 much larger than this. We will justify this assumption O(n log n) and O(m · minfm ; n g), respectively. by showing that for every graph G = (V; E) there is a Despite previous attempts, for sparse graphs no better graph G0 = (V 0;E0) such that jE0j = O(jEj), V ⊆ V 0 than O(m3=2) total update time algorithm was found. and jV 0j = O(jV j), every vertex v0 2 V 0 has degree at In this paper we present a Las Vegas randomized most O(jE0j=jV 0j) = O(jEj=jV j), and for any pair of algorithm that improves upon the state of the art for a vertices u; v 2 V , there is u − v path in G0 iff there is large spectrum of graph sparsity { namely, when m is 0 3=2 such a path in V ; thus, in particular, G has a cycle iff G !(n log(n)) and o(n ). does. This reduction justifies the following assumption; the proof of the reduction is deferred to Section A. Theorem 1.1 There exists an incremental algorithm for dynamicp cycle detection with expected total update Assumption 1.1 We assume for the rest of the paper time O(m n log(n)), where m refers to the number of that every vertex in the current graph G = (V; E) has edges in the final graph. degree O(jEj=jV j) = O(m=n); recall that n = jV j and m = jEfinalj. Theorem 1.2 There is an algorithm for incremen- 2 High Level Overview of Techniques tal topologicalp sortp with expected total update time O(m n log(n) + n n log2(n)). We now give a high level overview of our algorithm for incremental cycle detection; the algorithm for incremen- 1.1 Preliminaries In the incremental setting, we tal topological sort uses the same basic ideas, but is a start with an empty graph, and the adversary inserts good deal more involved. Let us consider the insertion directed edges one at a time. Let G always refer of a new edge (u; v). We want to determine if (u; v) to the current version of the graph. The update created a cycle. The trivial algorithm would be to do sequence terminates once G has a cycle; let Gfinal = a forward search from v, and see if it reaches vertex u, (V; Efinal) refer to the final version of the graph before but this requires O(m) time. We would like to prune the update that led to a cycle, let let m = jEfinalj, and the set of vertices that we have to search from v. Let let n = jV j. We will often speak of the update sequence us say that two vertices x and y are equivalent if they up to Gfinal, which excludes the very last update if are related and A(x) = A(y) and D(x) = D(y); it is it leads a cycle; thus the graph remains acyclic during easy to see that if two vertices are on a cycle, then they the entire update sequence up to Gfinal. Since edges are equivalent. Thus, when we insert edge (u; v), our are only inserted, any topological sort for Gfinal is forward search from v only needs to look at vertices also a topological sort for the current graph G. For the equivalent to v. sake of our analysis we fix some topological sort Tfinal Unfortunately efficiently maintaining equivalent of Gfinal; thus, for every (x; y) 2 Efinal we have vertices is at least as hard as finding a cycle.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    14 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us