An almost linear fully dynamic reachability algorithm Liam
An almost linear fully dynamic reachability algorithm Liam Roditty and Uri Zwick Tel Aviv University 1
Fully dynamic reachability The problem: Answer reachability queries on a directed graph that undergoes a sequence of edge insertions and deletions. 6 5 1 7 Insertion Center ? Query(7, 2) Query(8, 3) 8 4 3 2 9 Yes No If only deletions are allowed the algorithm is said to be decremental. 2
Fully dynamic reachability Approach 1: Maintain explicitly the transitive closure matrix. Query is done in O(1), each update may take (n 2) time. 3
Fully dynamic reachability Approach 1: Maintain explicitly the transitive closure matrix. Query is done in O(1), each update may take (n 2) time. n 2 4
Fully dynamic reachability Approach 1: Maintain explicitly the transitive closure matrix. Query is done in O(1), each update may take (n 2) time. Approach 2: A data structure which may have a nonconstant query time but with smaller update time. Open problem: Is it possible to break the (n 2) barrier Our result: Updates in O(m+n log n) and queries in O(n) 5
Fully dynamic reachability Graphs Algorithm Amortized Query Author update time General Deterministic n 2 1 Demetrescu, Italiano ’ 00 Roditty ’ 03 DAGs Monte-Carlo n 1. 58 n 0. 58 Demetrescu, Italiano ’ 00 General Monte-Carlo mn 1/2 log 2 n n log n Henzinger King ’ 95 General Deterministic mn 1/2 Roditty Zwick ’ 02 General Deterministic m + n log n n Today 6
An overview of the algorithm Insert(Ew) – Insert the edges Ew all touching w into the graph Delete(E’ ) – Delete all edges of E’ from the graph Query(u, v) – Check whethere is a directed path from u to v G 1(V, E 1=Ev 1) G 2(V, E 2=E 1 Ev 2) G 3(V, E 3=E 2 Ev 3) u Tin(w) w Tout(w) Gt(V, Et=Et-1 Evt) v 1 v 2 v 3 … vt v Insert(Ev 1) Insert(Ev 2) Insert(Ev 3) Insert( Ew ) : Create two trees to capture new paths Query(u , v ): w, u Tin(w) v Tout(w) Delete( E’ ): Delete E’ from all trees Insert(Evt) O (m+n log n O ) (n ) O (m+n log n ) Once created a graph can only lose edges ! Our goal is to delete edges efficiently 7
Decremental reachability tree Suppose that the graph is DAG (Italiano `88), v Tin(w) w Tout(w) Every edge is only examined once thus the total time is O(m). 8
For general graphs the cost for a single decremental reachability tree is O(mn)! We reduce the cost to O(m+n logn) for a tree in a forest of trees! v 1 v 2 G 1(V, E 1) G 2(V, E 2) … vt Gt(V, Et) • Maintain the components of a sequence of graphs • Keep the rule that each edge is scanned only once • Build the new component data after each decomposition. 9
An overview of the algorithm Fully dynamic reachability Fully dynamic strong connectivity with “persistency” Decremental reachability tree n Decremental reachability tree Maintain the components of a sequence of graphs Keep the rule that each edge is scanned only once Build the new component data after each decomposition. By combining this two ingredients we obtain an efficient maintenance of the forest of reachability trees. 10
Fully dynamic strong connectivity Supported operations: Insert( E’ ) – Create a new version and add E’ to it. O (m (m, n)) Delete( E’ ) – Delete the set E’ from all versions. Query(u, v, i) – Are u and v in the same component in Gi O (1 ) Insert(E’) G 0=(V, E 0) GG 1=(V, E 1)E’) 1=(V, E 0 Insert(E’’) GG 2=(V, E 2)E’’) 2=(V, E 1 Note that these operations create a graph sequence G 0(V, E 0), G 1(V, E 1), … , Gt(V, Et) where E 0 E 1 … Et. This containment is kept during all the update operations! 11
Fully dynamic strong connectivity The components of all the graphs in the sequence arranged in a hierarchy and can be represented as a forest of size O (n ) The components: G 0 G 1 G 2 G 3 The forest: G 0 G 1 G 2 1 G 3 Version tag u 1 v 2 1 3 Query(u, v, 1) Version( LCA(u, v) ) 1 Query(u, v, 2) Version( LCA(u, v) ) 2 12
A new partitioning of the edges E 1, …, Et Definition 1: Dynamic edge partitioning Hi = { (u, v) Ei | Query(u, v, i) ( Query(u, v, i-1) (u, v) Ei-1) } t Ht+1 = Et Hi i=1 Gi=(V, Ei) Gi-1=(V, Ei-1) Hi Gi+1=(V, Ei+1) Hi+1 t+1 Hi Hj = ø, Et =i=1 Hi 13
Processing a deletion G 0 Find. Scc(H 1, 1) Shift(H 1, H 2) G 1 Find. Scc(H 2, 2) Shift(H 2, H 3) G 2 Find. Scc(H 3, 3) Shift(H 3, H 4) G 3 Hi edges Cost Analysis: Note that an edge enters and leave Hi just once Moving edges – Paid by the creation of the version they enter. Free Fixed edges – Paid by the current delete operation O(m) 14
The component forest G 0 G 1 G 2 G 3 15
Fully dynamic strong connectivity Summing up, • The update time is O (m (m, n)) and the query time is O (1 ). • The vertices of any component can be listed in time proportional to the size of the component. • Given two component forests of before and after a deletion it is possible to find all the decomposed components. • The size of the data structure is O(m+n) 16
Decremental reachability tree Active vertices list Tree edge When a decomposition is reported : • Build the active vertices list for the new components • Connect the new components to the tree 17
Decremental reachability tree There may be O(n) decompositions in a single tree. Thus, even scanning the decomposed component vertices in order to build the active vertices list for the new components is too much. The total cost may be O(n 2). We succeeded to reduce this cost to O(n log n) ! 18
Decremental reachability tree Summing up, for each tree • The total connection cost is O(m) • The total decomposition cost is O(n log n) For the whole forest the components are maintained in O(m (m, n)) for each update Each update costs O(m + n log n) 19
Open problems • Reduce the query time to m/n ? • Reduce the update time to O(m+n) ? • Design other fully dynamic algorithm for a graph sequence ? • A single decremental reachability tree in general graph in o(mn) ? 20
- Slides: 20